From 3bd7fa3bb4e950dcb256fff3c923dbea7d1fb349 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Tue, 12 Nov 2024 20:47:31 +1100 Subject: [PATCH] local-store: fix infinite loop on Windows Also switch to std::filesystem. --- src/libstore/local-store.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index eafdac0cd33..f9529178697 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -212,16 +212,15 @@ LocalStore::LocalStore( /* Ensure that the store and its parents are not symlinks. */ if (!settings.allowSymlinkedStore) { - Path path = realStoreDir; - struct stat st; - while (path != "/") { - st = lstat(path); - if (S_ISLNK(st.st_mode)) + std::filesystem::path path = realStoreDir.get(); + std::filesystem::path root = path.root_path(); + while (path != root) { + if (std::filesystem::is_symlink(path)) throw Error( "the path '%1%' is a symlink; " "this is not allowed for the Nix store and its parent directories", path); - path = dirOf(path); + path = path.parent_path(); } }