From 44d5bd4789ded74eac6f717bd5c6686908f75ac6 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Thu, 9 Jun 2022 23:50:20 +0200 Subject: [PATCH] Follow symlinks --- src/libfetchers/zip-input-accessor.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libfetchers/zip-input-accessor.cc b/src/libfetchers/zip-input-accessor.cc index 8b820bbf3c3..be55dc53121 100644 --- a/src/libfetchers/zip-input-accessor.cc +++ b/src/libfetchers/zip-input-accessor.cc @@ -78,10 +78,19 @@ struct ZipInputAccessor : InputAccessor std::string readFile(const CanonPath & path) override { - if (lstat(path).type != tRegular) - throw Error("file '%s' is not a regular file", path); + auto type = lstat(path).type; + + if (type == tRegular) + return _readFile(path); + + if (type == tSymlink) { + auto parent = path.parent(); + if (parent.has_value()) + return readFile(parent.value() + CanonPath(readLink(path))); + } + + throw Error("file '%s' is not a regular file", path); - return _readFile(path); } bool pathExists(const CanonPath & path) override