Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys::Path enhancements #1161

Closed
lattner opened this issue May 30, 2006 · 7 comments
Closed

sys::Path enhancements #1161

lattner opened this issue May 30, 2006 · 7 comments
Labels
bugzilla Issues migrated from bugzilla enhancement Improving things as opposed to bug fixing, e.g. new or missing feature portability

Comments

@lattner
Copy link
Collaborator

lattner commented May 30, 2006

Bugzilla Link 789
Resolution FIXED
Resolved on Feb 22, 2010 12:44
Version 1.0
OS All

Extended Description

I have been working on some code that will hopefully land in LLVM at some point, and it needs to
efficiently grovel through the file system. Here are a few things that libsystem should do that it doesn't
currently:

  1. Implement sys::Path::isAbsolute(), which returns true if the path is an absolute path (e.g. on Unix,
    starts with /, on win32, starts with c:\ or \network\device).
  2. Given a directory name and a filename (maybe with a partial directory on it) append them correctly.
    Right now I'm using (dir + "/" + file), which works fine on unix, but sucks on win32. :)
  3. GetStatus does not return inode/device ID numbers. I want to have some way to uniquely identify
    files, even those that are symlinked together. If the st_dev/st_ino fields of two files match, they are the
    same, but Path::getStatus doesn't expose these.
  4. Given a path to a file, strip off the filename and return just the directory. For "/foo/bar" it should
    return "/foo" for "bar" it should return "." on unix.
  5. It would be double plus good to have an interface to enumerate the files in a directory.

In terms of efficiency enhancements, it would be nice if sys::Path cached the status returned by stat, so
that calls to things like getSize etc, didn't restat for every call. It would also be nice if MappedFile took
in a file size argument so that you could map a file (which was previously stat'ed) without having
MappedFile restat it. If sys::Path cached the Status info, it would be natural to pass a path to
MappedFile to make this all transparent.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented May 30, 2006

Oh yeah, one trivial improvement to MappedFile would remove a syscall:

void MappedFile::initialize() {
if (path_.exists()) {
info_ = new MappedFileInfo;
...
info_->fd_ = ::open(path_.c_str(),mode);

if (info_->fd_ < 0) {
  delete info_;
  info_ = 0;
  ThrowErrno(std::string("Can't open file: ") + path_.toString());
}

There is no reason to call Path::exists (a syscall). Instead, just call open, and if it fails, you know the file
doesn't exist. Also, the error path code would be simpler and faster if MappedFileInfo were allocated
later.

-Chris

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 29, 2007

  1. is easy, will do.
  2. is already supported with the appendComponent method
  3. can't be made to work portably without a lot of fudging. Windows has no
    concept of links and so no "unique identity" for files. About the only thing
    that could be done is generate an md5sum on the file name and hope that it
    doesn't collide
  4. Use eraseComponent.
  5. Use getDirectoryContents

The FileStauts info will be cached in my next commit.

@lattner
Copy link
Collaborator Author

lattner commented Mar 30, 2007

Thanks Reid!!

Question, isn't \network\device\blah absolute on win32?

-Chris

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 30, 2007

Yes, it is. And, Jeff C already fixed it :)

Since I can't (easily) compile for win32, I just write place holders and Jeff
cleans it up.

There's one remaining issue for this: uniqueness of Paths via the UniqueID field
of the FileStatus structure. It will work fine on Unix (Inode #) but currently
won't work well on Win32 unless the path strings are identical. Jeff has a way
to get a unique id for each file from Win32, but the file has to be open first!
(go figure).

So, this is currently an unresolved issue on win32 port. Perhaps I should open
a bug for that.

@lattner
Copy link
Collaborator Author

lattner commented Mar 30, 2007

Jeff C already fixed it :)

Ah, woot!

So, this is currently an unresolved issue on win32 port. Perhaps I should open
a bug for that.

Okay, either way. Since we don't have a client for this yet, it isn't a big deal.

It will work fine on Unix (Inode #)

This needs to be an inode/volume number pair,

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Endilll Endilll added enhancement Improving things as opposed to bug fixing, e.g. new or missing feature and removed new-feature labels Aug 15, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla enhancement Improving things as opposed to bug fixing, e.g. new or missing feature portability
Projects
None yet
Development

No branches or pull requests

3 participants