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

(PUP-5018) Cannot unlink dangling Windows symlinks #4147

Conversation

Iristyle
Copy link
Contributor

  • When a symlink is created to point at a directory, then that target
    directory is removed, Windows was previously generating
    Errno::EACCES: Permission denied @ unlink_internal because the
    underlying Ruby File.unlink was being called, which fails on Windows.

    When the target no longer exists, Ruby's File.unlink only works
    properly on symlinks pointed at files and not symlinks pointed at
    directories

    Given the lstat only specifies 'link' and does not describe the
    target, there is no way of knowing whether the former target was a
    file or directory. Thefore, when the target stat does not exist,
    first attempt to File.unlink, and if that fails call Dir.rmdir.
    Ruby's Dir.rmdir only works on links that were targeted at
    directories, and not links that were targeted at files.

@@ -62,7 +62,9 @@ def unlink(*file_names)
stat = Puppet::Util::Windows::File.stat(file_name) rescue nil

# sigh, Ruby + Windows :(
if stat && stat.ftype == 'directory'
if !stat
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I understand what you meant by nil coming back.

@Iristyle Iristyle force-pushed the ticket/stable/PUP-5018-Windows-unlink-fails-on-orphaned-links branch from a599f60 to da86ca3 Compare August 10, 2015 21:13
@ferventcoder
Copy link
Contributor

Once it's green it's gold.

Puppet::FileSystem.unlink(symlink)

expect(Puppet::FileSystem.exist?(dir)).to be_falsey
expect(Puppet::FileSystem.exist?(dir)).to be_falsey
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh shoot.. typo here.

@Iristyle Iristyle force-pushed the ticket/stable/PUP-5018-Windows-unlink-fails-on-orphaned-links branch from da86ca3 to ba44550 Compare August 10, 2015 21:37
::File.delete(file)
Puppet::FileSystem.unlink(symlink)

expect(Puppet::FileSystem.exist?(file)).to be_falsey
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit, for predicate methods you'll get better error messages if you do something like:

expect(Puppet::FileSystem).to_not be_exist(file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 repushed

 - When a symlink is created to point at a directory, then that target
   directory is removed, Windows was previously generating
   `Errno::EACCES: Permission denied @ unlink_internal` because the
   underlying Ruby File.unlink was being called, which fails on Windows.

   When the target no longer exists, Ruby's File.unlink only works
   properly on symlinks pointed at files and not symlinks pointed at
   directories.

   Given the lstat only specifies 'link' and does not describe the
   target, there is no way of knowing whether the former target was a
   file or directory.  Thefore, when the target stat does not exist,
   first attempt to File.unlink, and if that fails call Dir.rmdir.
   Ruby's Dir.rmdir only works on links that were targeted at
   directories, and not links that were targeted at files.
@Iristyle Iristyle force-pushed the ticket/stable/PUP-5018-Windows-unlink-fails-on-orphaned-links branch from ba44550 to 579d5ea Compare August 12, 2015 21:17
@ferventcoder
Copy link
Contributor

This looks good to move in.

ferventcoder added a commit that referenced this pull request Aug 13, 2015
…-unlink-fails-on-orphaned-links

(PUP-5018) Cannot unlink dangling Windows symlinks
@ferventcoder ferventcoder merged commit d70c351 into puppetlabs:stable Aug 13, 2015
@ferventcoder
Copy link
Contributor

Merged to master at 7a87738

@Iristyle Iristyle deleted the ticket/stable/PUP-5018-Windows-unlink-fails-on-orphaned-links branch August 11, 2016 17:16
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.

None yet

3 participants