Skip to content

Commit

Permalink
Don't dereference top-level regular files
Browse files Browse the repository at this point in the history
Since this yielded an empty directory as far back as Nix 2.3, we don't
really need special handling for executables vs non-executables.
  • Loading branch information
edolstra committed Jul 29, 2024
1 parent e0012b9 commit 7c18b4d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,13 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
{
auto oid = hashToOID(oid_);

/* If the root directory contains */
auto _tree = lookupObject(*this, oid, GIT_OBJECT_TREE);
auto tree = (const git_tree *) &*_tree;

if (git_tree_entrycount(tree) == 1) {
auto entry = git_tree_entry_byindex(tree, 0);
auto mode = git_tree_entry_filemode(entry);
if (mode == GIT_FILEMODE_BLOB || mode == GIT_FILEMODE_TREE)
if (mode == GIT_FILEMODE_TREE)
oid = *git_tree_entry_id(entry);
}

Expand Down
7 changes: 1 addition & 6 deletions src/libfetchers/git-utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ struct GitRepo

/**
* If the specified Git object is a directory with a single entry
* that is a directory or a non-executable regular file, return
* the ID of that object.
*
* Note: We don't do this for executable files because they don't
* have a tree hash in the Git object model that distinguishes
* them from non-executable files.
* that is a directory, return the ID of that object.
*/
virtual Hash dereferenceSingletonDirectory(const Hash & oid) = 0;
};
Expand Down
10 changes: 1 addition & 9 deletions tests/functional/tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,7 @@ path="$(nix flake prefetch --json "tarball+file://$TEST_ROOT/tar.tar" | jq -r .s
[[ -d "$path/foo" ]]
[[ -d "$path/bar" ]]

# Test a tarball that has a single non-executable regular file.
rm -rf "$TEST_ROOT/tar_root"
mkdir -p "$TEST_ROOT/tar_root"
echo bar > "$TEST_ROOT/tar_root/foo"
tar cvf "$TEST_ROOT/tar.tar" -C "$TEST_ROOT/tar_root" .
path="$(nix flake prefetch --refresh --json "tarball+file://$TEST_ROOT/tar.tar" | jq -r .storePath)"
[[ $(cat "$path") = bar ]]

# Test a tarball that has a single executable regular file.
# Test a tarball that has a single regular file.
rm -rf "$TEST_ROOT/tar_root"
mkdir -p "$TEST_ROOT/tar_root"
echo bar > "$TEST_ROOT/tar_root/foo"
Expand Down

0 comments on commit 7c18b4d

Please sign in to comment.