Skip to content

Commit

Permalink
Merge pull request #478 from Earlopain/store-with-broken-symlink
Browse files Browse the repository at this point in the history
Fix startup failure if the cache directory points to a broken symlink
  • Loading branch information
casperisfine committed Mar 5, 2024
2 parents 8394834 + aef82de commit 9210a2e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/bootsnap/load_path_cache/store.rb
Expand Up @@ -122,6 +122,8 @@ def mkdir_p(path)
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
Expand Down
7 changes: 7 additions & 0 deletions test/load_path_cache/store_test.rb
Expand Up @@ -85,6 +85,13 @@ def test_retry_on_collision
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) }
Expand Down

0 comments on commit 9210a2e

Please sign in to comment.