-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Added ismount function. #11279
Added ismount function. #11279
Conversation
Seems harmless enough to have, non-exported. Could use a test though. |
+1 |
OK, I'll add one. |
Should probably be exported (see |
Docs wouldn't hurt, but is this widely used enough to export right away? |
function ismount(path...) | ||
path = abspath(joinpath(path...)) | ||
isdir(path) || return false | ||
parent_path = splitdir(path)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on linux, this is not necessarily the same as the parent directory.
If we add it so that people can use it outside of Base, better assume it by exporting the function IMHO. Else this is just pushing people into relying on unofficial APIs. And since Python has it, it's probably worth having too (though it will probably have to move to a separate module when Base is refactored). |
Sounds good for now, on both counts. We should probably move a bunch of things to an |
@vtjnash Good points. I'll look up the Python implementation and modify mine to be semantically identical. |
I think it is a bad idea to add unexported functions to Base (unless they are an implementation detail of other functions). I'm also negative to introducing a new function that we expect to move, so if we want a (sorry for closing, it was not intentional) |
FS is not a good name for a module - we should respect the package naming rules. Better FileSystem |
I am with @ivarne here. If things in Base are not important enough to be exported, then they should simply not be part of Base. |
Good point.
There's a point there too, but I'm not sure if the onus should be on @malmaud who wants to add one function that has plenty of precedent in other languages, to undertake a major reorganization first. Anyone want to volunteer? I'll add it to my to-do list but might not get to it before 0.4.0. |
Just for reference, this is the Python implementation: def ismount(path):
"""Test whether a path is a mount point"""
try:
s1 = os.lstat(path)
except OSError:
# It doesn't exist -- so not a mount point. :-)
return False
else:
# A symlink can never be a mount point
if stat.S_ISLNK(s1.st_mode):
return False
if isinstance(path, bytes):
parent = join(path, b'..')
else:
parent = join(path, '..')
try:
s2 = os.lstat(parent)
except OSError:
return False
dev1 = s1.st_dev
dev2 = s2.st_dev
if dev1 != dev2:
return True # path/.. on a different device as path
ino1 = s1.st_ino
ino2 = s2.st_ino
if ino1 == ino2:
return True # path/.. is the same i-node as path
return False |
Alright, I added docs and make it compatible with the Python definition of a mount point. Not sure how to add a test unless a test can be a fixture that actually mounts a volume. Is that possible in Julia's testing framework? |
Let's merge this since it seems like reasonable and useful functionality and open a separate issue for figuring out how to test it. |
Added ismount function.
Equivalent functionality of Python's
os.path.ismount
function: