Skip to content

Commit

Permalink
Remove target path's forward slashes in File.symlink on Windows (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored May 1, 2024
1 parent 8b9e299 commit 0f35ff7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ describe "File" do
File.same?(in_path, out_path, follow_symlinks: true).should be_true
end
end

it "works if destination contains forward slashes (#14520)" do
with_tempfile("test_slash_dest.txt", "test_slash_link.txt") do |dest_path, link_path|
File.write(dest_path, "hello")
File.symlink("./test_slash_dest.txt", link_path)
File.same?(dest_path, link_path, follow_symlinks: true).should be_true
File.read(link_path).should eq("hello")
end
end
end

describe "symlink?" do
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ module Crystal::System::File
end

def self.symlink(old_path : String, new_path : String) : Nil
win_old_path = System.to_wstr(old_path)
win_old_path = System.to_wstr(old_path.gsub('/', '\\'))
win_new_path = System.to_wstr(new_path)
info = info?(old_path, true)
flags = info.try(&.type.directory?) ? LibC::SYMBOLIC_LINK_FLAG_DIRECTORY : 0
Expand Down

0 comments on commit 0f35ff7

Please sign in to comment.