LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1291 - sys::Path enhancement: add PathWithStatus
Summary: sys::Path enhancement: add PathWithStatus
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: System Library (show other bugs)
Version: 1.0
Hardware: Macintosh MacOS X
: P enhancement
Assignee: Reid Spencer
URL:
Keywords: code-cleanup, new-feature
Depends on:
Blocks:
 
Reported: 2007-03-30 01:43 PDT by Chris Lattner
Modified: 2010-02-22 12:40 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-03-30 01:43:10 PDT
Getting the status of a sys::path curently requires new'ing the status object.  It would be nice if we 
could make a subclass PathWithStatus, and move the 'status' related stuff there.  This would give us 
something like this:

class PathWithStatus : public Path {
   Status S;
   bool IsStatusValid;
}

If you sink the 'status gathering' methods out of Path into  
PathWithStatus, then you let the client decide whether they want to  
store a status or not, and if they want it, they don't have to pay for a separate malloc.

-Chris
Comment 1 Reid Spencer 2007-04-07 11:56:21 PDT
This isn't quite trivial. A lot of regular "Path" methods depend on the ability
to get the file status. For example, the "isExecutable" method has to check both
the access bits *and* determine if its a regular file. The method wants to only
indicate true for executable files, not searchable directories. Consequently it
needs the stat information. 

There are several other examples of these that I'm not quite sure how to
resolve. From an API perspective it doesn't make sense to move these methods to
PathWithStatus. From a performance perspective, it doesn't make sense to
instantiate a PathWithStatus temporarily in the body of such methods. 

I'll work on this and come up with a solution.
Comment 2 Reid Spencer 2007-04-07 13:49:56 PDT
The solution is to just use stat(2) directly. In all of these cases it would be
bad if we were using stale stat information so the "force udpate" parameter was
being passed to getFileStatus anyway which means that just using stat(2)
directly preserves current behavior and simplifies things a lot.
Comment 3 Reid Spencer 2007-04-07 13:55:49 PDT
Implemented with these patches:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070402/046965.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070402/046966.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070402/046967.html

Jeff:
I think I got the Win32 part of this right, but it hasn't been compiled. Could
you please try it and verify on Win32?
Comment 4 Chris Lattner 2007-04-07 15:29:02 PDT
Question: why not move isExecutable etc to PathWithStatus?

-Chris
Comment 5 Reid Spencer 2007-04-07 15:36:13 PDT
Because isReadable and isWritable need to be on Path and it didn't seem like a
good API decision to move it to PathWithStatus. As I described, however, this
needs re-stat on each call in case the status changed since the last time it was
checked. So, the current approach (always stat) is both correct and equivalent
to what we had previously when getFileStatus was part of Path class.

Its also less impact to LLVM to leave it in Path class.