Fix startup failure if the cache directory points to a broken symlink

This commit is contained in:
Earlopain 2024-03-04 16:19:42 +01:00
parent 8394834cd5
commit aef82de32c
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
3 changed files with 11 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# Unreleased
* Fix startup failure if the cache directory points to a broken symlink.
# 1.18.3
* Fix the cache corruption issue in the revalidation feature. See #474.

View File

@ -122,6 +122,8 @@ module Bootsnap
stack.reverse_each do |dir|
Dir.mkdir(dir)
rescue SystemCallError
# Check for broken symlinks. Calling File.realpath will raise Errno::ENOENT if that is the case
File.realpath(dir) if File.symlink?(dir)
raise unless File.directory?(dir)
end
end

View File

@ -85,6 +85,13 @@ module Bootsnap
store.transaction { store.set("a", 1) }
end
def test_with_broken_symlink
FileUtils.ln_s(@path, "#{@dir}/store_broken")
store = Store.new("#{@dir}/store_broken/store")
store.transaction { store.set("a", "b") }
end
def test_ignore_read_only_filesystem
MessagePack.expects(:dump).raises(Errno::EROFS.new("Read-only file system @ rb_sysopen"))
store.transaction { store.set("a", 1) }