From aef82de32c622443780bc2ab0d54451225ecc318 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:19:42 +0100 Subject: [PATCH] Fix startup failure if the cache directory points to a broken symlink --- CHANGELOG.md | 2 ++ lib/bootsnap/load_path_cache/store.rb | 2 ++ test/load_path_cache/store_test.rb | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1859174..9636e63 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/lib/bootsnap/load_path_cache/store.rb b/lib/bootsnap/load_path_cache/store.rb index 52460b8..eaeb009 100644 --- a/lib/bootsnap/load_path_cache/store.rb +++ b/lib/bootsnap/load_path_cache/store.rb @@ -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 diff --git a/test/load_path_cache/store_test.rb b/test/load_path_cache/store_test.rb index 21b5a05..cc967f2 100644 --- a/test/load_path_cache/store_test.rb +++ b/test/load_path_cache/store_test.rb @@ -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) }