[PUP-5018] Puppet::FileSystem.unlink fails on Windows when the target path doesn't exist Created: 2015/08/10  Updated: 2015/09/14  Resolved: 2015/08/14

Status: Closed
Project: Puppet
Component/s: Windows
Affects Version/s: PUP 4.2.0
Fix Version/s: PUP 4.2.2

Type: Bug Priority: Normal
Reporter: Rob Reynolds Assignee: Ryan Gard
Resolution: Fixed Votes: 0
Labels: windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File console.png     PNG File repro.png    
Issue Links:
relates to MODULES-2175 DSC - Create Symlinks with Ruby Inste... Resolved
Story Points: 2
Sprint: Windows 2015-08-26
Release Notes: Bug Fix
Release Notes Summary: There was a an issue with removing a symlink that links to a target that no longer exists. It would cause Puppet to error. This fixes that behavior so the symlink is removed without error.
QA Contact: Ryan Gard


When attempting to delete a symlink on Windows for a target path that no longer exists, Puppet throws a Permission Denied error.

This was discovered during the work for MODULES-2175.

[1] pry(DscSymlink)> e.class
=> Errno::EACCES

Expected: The link should be removed.

Repro: To reproduce, create a symlink, delete the target path and then try to unlink it:

    it "should unlink a symlink if the existing link path does not exist" do
      path =   Dir.mktmpdir('test')
      symlink_path = "#{path}\\link"
      link_target = Dir.mktmpdir('link_test')
      Puppet::FileSystem.symlink(link_target, symlink_path, { :force => true})
      system("rmdir /s /q \"#{link_target}\"")

Comment by Rob Reynolds [ 2015/08/10 ]

The handling for this in DSC was done by falling back to regular move/delete methods - https://github.com/puppetlabs/puppetlabs-dsc/commit/cc91b358cb976e58e3ec8eaabf1a57c54377a756

Comment by Rob Reynolds [ 2015/08/13 ]

Merged into stable at https://github.com/puppetlabs/puppet/commit/d70c351b0bde0b36aa528ddf7a4129fa34a96a0c
Merged into master at https://github.com/puppetlabs/puppet/commit/7a87738f9aaafcfe5171d71820047df418471e76

Comment by Rob Reynolds [ 2015/08/13 ]

Passed stable specs https://jenkins.puppetlabs.com/view/All%20in%20One%20Agent/view/Stable/view/Puppet/job/platform_aio-puppet_stage-unit_stable/397/
Passed master specs https://jenkins.puppetlabs.com/view/All%20in%20One%20Agent/view/Master/view/Puppet/job/platform_aio-puppet_stage-unit_master/175/

But did not pass acceptance due to newly found beaker issue (JIRA ticket yet to be determined).

Comment by Ryan Gard [ 2015/08/13 ]

Functional Review

Verified as fixed in Puppet Agent build


Puppet Agent Version:
Agent: Windows 2012 R2 x64

Repro Steps

  1. Install Puppet Agent on Windows node.
  2. Create the following manifest "create_link.pp" on the SUT:

    file { 'create_original_dir':
      ensure  => directory,
      path    => 'C:/test'
    file { 'create_original_file':
      ensure  => file,
      path    => 'C:/test/test.file',
      content => 'stuff'
    file { 'create_dir_link':
      ensure => link,
      path   => 'C:/link_dir',
      target => 'C:/test'
    file { 'create_file_link':
      ensure => link,
      path   => 'C:/link.file',
      target => 'C:/test/test.file'

  3. Create the following manifest "delete_link.pp" on the SUT:

    file { 'delete_original_dir':
      ensure => absent,
      path   => 'C:/test',
      force  => true 
    file { 'delete_dir_link':
      ensure => absent,
      path   => 'C:/link_dir'
    file { 'delete_file_link':
      ensure => absent,
      path   => 'C:/link.file'

  4. Apply the "create_link.pp" manifest on the SUT:

    puppet apply create_link.pp

  5. Verify links are valid:
    type c:\link.file
    type c:\link_dir\test.file
  6. Apply the "delete_link.pp" manifest on the SUT:

    puppet apply delete_link.pp


The Puppet apply should complete successfully with all files and links removed.


Comment by Rob Reynolds [ 2015/08/14 ]

Ryan Gard this looks okay. I think that if you don't get a repro, you should probably switch to manual deletion of the original folders (not the symlinks) outside of Puppet, then follow it up with a delete for the symlinks with Puppet.

Comment by Rob Reynolds [ 2015/08/14 ]

Actually now that I think about it, it may just treat the files regularly when you go to remove the symlinks. It may be that the only way to see the repro is to work with the code directly. I think first try to produce the repro using puppet manifests and see if it is possible or just more of a hidden issue that can only be reached through code.

It repros just fine

Comment by Kylo Ginsberg [ 2015/09/03 ]

Rob Reynolds can you update the two release notes fields for this ticket? Thanks!

Comment by Rob Reynolds [ 2015/09/04 ]

Release notes fields updated!

Generated at Mon Sep 28 13:54:45 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.