Install builder: remove target file before copying to avoid errors due to overwriting read-only files - close #123

This commit is contained in:
Josh Holtrop 2021-02-23 15:20:59 -05:00
parent b970490de2
commit b92360d4e2
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Rscons::Environment.new do |env|
env.Install("dest", "install.rb")
end

View File

@ -47,6 +47,7 @@ module Rscons
printed_message = true
end
cache.mkdir_p(File.dirname(dest))
FileUtils.rm_f(dest)
FileUtils.cp(src, dest, :preserve => true)
end
cache.register_build(dest, :Copy, [src], env)

View File

@ -1002,6 +1002,22 @@ EOF
expect(lines(result.stdout)).to eq ["Install inst.exe"]
end
it "overwrites a read-only file" do
test_dir("build_dir")
FileUtils.chmod("a=r", "install.rb")
result = run_test(rsconsfile: "install_read_only.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install dest"]
FileUtils.rm_f("install.rb")
File.binwrite("install.rb", "hi")
FileUtils.chmod("a=r", "install.rb")
result = run_test(rsconsfile: "install_read_only.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install dest"]
end
it "operates the same as a Copy builder" do
test_dir("build_dir")