From a8546894245f770349dd6811c45fd5c560677ed1 Mon Sep 17 00:00:00 2001 From: Ashley Donaldson Date: Fri, 11 Oct 2024 21:17:51 +1100 Subject: [PATCH] Added new failing test for windows junction points --- test/modules/post/test/file.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/modules/post/test/file.rb b/test/modules/post/test/file.rb index db6cf38b9659..0affc3433382 100644 --- a/test/modules/post/test/file.rb +++ b/test/modules/post/test/file.rb @@ -117,6 +117,27 @@ def test_dir ret end end + + if (session.platform == 'windows') + it 'should delete a junction target' do + mkdir(datastore['BaseDirectoryName']) + ret = directory?(datastore['BaseDirectoryName']) + link = "#{datastore['BaseDirectoryName']}.junc" + ret &&= write_file([datastore['BaseDirectoryName'], 'file'].join(fs_sep), '') + make_junction(datastore['BaseDirectoryName'], link) + unless exists?(link) + print_error('failed to create the symbolic link') + end + rm_rf(link) + # the link should have been deleted + ret &&= !exists?(link) + # but the target directory and its contents should still be intact + ret &&= exists?("#{[datastore['BaseDirectoryName'], 'file'].join(fs_sep)}") + rm_rf(datastore['BaseDirectoryName']) + ret + end + end + end def test_file @@ -289,6 +310,10 @@ def test_path_expansion_nix end end + def make_junction(target, symlink) + cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/J ' : ''}#{symlink} #{target}") + end + def make_symlink(target, symlink) if session.platform == 'windows' cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/D ' : ''}#{symlink} #{target}")