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

Add option to hardlink when importing #2445

Merged
merged 8 commits into from
Feb 21, 2017
Merged

Add option to hardlink when importing #2445

merged 8 commits into from
Feb 21, 2017

Conversation

jacobwgillespie
Copy link
Contributor

This PR adds an option to hardlink files when importing, similar to the existing link option that enables symlinks. Tests in the same style as the symlink tests are included.

import:
    write: no
    hardlink: yes

raise FilesystemError(exc, 'link', (path, dest),
traceback.format_exc())


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part about windows version less than 6 needs to go. I don't think they are supported on windows at all, on any version.

@ghost
Copy link

ghost commented Feb 19, 2017

I think we also need to add a check to make sure both the source and the target are on the same device, otherwise the hardlink will fail. Simply copying what symlinks do is not enough.

@ghost
Copy link

ghost commented Feb 19, 2017

Writing a proper test for this will probaby require creating a fake device using tmpfs or the like

@jacobwgillespie
Copy link
Contributor Author

jacobwgillespie commented Feb 19, 2017

I added a catch for the cross-device hardlink error so that the error's a bit prettier, however I'm not sure how to handle the test. tmpfs would indeed work, but it doesn't exist on OS X. Perhaps the implementation is simple enough at this point that we could get away without a cross-device hardlink test, we'd essentially be testing the Python implementation of os.link.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good so far! I have a few suggestions about the link function itself.

"""Create a hard link from path to `dest`. Raises an OSError if
`dest` already exists, unless `replace` is True. Does nothing if
`path` == `dest`."""
if (samefile(path, dest)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No parentheses are necessary around the function call.

def hardlink(path, dest, replace=False):
"""Create a hard link from path to `dest`. Raises an OSError if
`dest` already exists, unless `replace` is True. Does nothing if
`path` == `dest`."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please place the closing """ on a line by itself (that's PEP8 style).

return

path = syspath(path)
dest = syspath(dest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might seem like a shortcut, but doing this once and overwriting the variables will cause problems: namely, the exceptions below use path and dest, which will now be system paths. This will produce strange results on Windows, where a ridiculous prefix needs to be added for syspath results.

It will fail on Windows.

It's likely that you'll also want to set ``write`` to ``no`` if you use this
option to preserve the metadata on the linked files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copying and pasting the above two paragraphs, can you please make this a little more human by saying something like:

As with symbolic links (see :ref:link, above), this will not work on Windows and you'll want to set write to no.

@jacobwgillespie
Copy link
Contributor Author

Thanks for the feedback - most of your suggestions applied to the original link method, so I updated that as well.

@sampsyo
Copy link
Member

sampsyo commented Feb 20, 2017

Ah, great! I hadn't realized that we had the same issues just above in the symlink function. Thanks for fixing that too.

@sampsyo
Copy link
Member

sampsyo commented Feb 21, 2017

Thank you again! This is all merged up. ✨

@sampsyo sampsyo merged commit 4e77ef4 into beetbox:master Feb 21, 2017
sampsyo added a commit that referenced this pull request Feb 21, 2017
Add option to hardlink when importing
sampsyo added a commit that referenced this pull request Feb 21, 2017
@jacobwgillespie
Copy link
Contributor Author

Sweet, thanks for the fast response 🎉

@jacobwgillespie jacobwgillespie deleted the hardlinks branch February 21, 2017 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants