Skip to content

Commit

Permalink
Update the contents of files.json
Browse files Browse the repository at this point in the history
New spec says:
- prefix_placeholder, no_link, and file_mode should only exist if they
  have vaules
- inode_first_path should instead be inode_paths that is a list of
  inodes that the file shares inodes with
  • Loading branch information
soapy1 committed Nov 14, 2016
1 parent 4f459d3 commit 3a225a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
22 changes: 11 additions & 11 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@


class FileType(Enum):
regular = "regular"
softlink = "softlink"
hardlink = "hardlink"
directory = "directory"
Expand Down Expand Up @@ -500,7 +499,7 @@ def is_no_link(no_link, short_path):
return True


def get_sorted_inode_first_path(files, target_short_path, prefix):
def get_inode_paths(files, target_short_path, prefix):
ensure_list(files)
target_short_path_inode = os.stat(join(prefix, target_short_path)).st_ino
hardlinked_files = [sp for sp in files
Expand All @@ -513,9 +512,7 @@ def file_type(path):
return FileType.directory
elif islink(path):
return FileType.softlink
elif os.stat(path).st_nlink >= 2:
return FileType.hardlink
return FileType.regular
return FileType.hardlink


def build_info_files_json(m, prefix, files, files_with_prefix):
Expand All @@ -529,13 +526,16 @@ def build_info_files_json(m, prefix, files, files_with_prefix):
"sha256": sha256_checksum(path),
"size_in_bytes": os.path.getsize(path),
"file_type": getattr(file_type(path), "name"),
"prefix_placeholder": prefix_placeholder,
"file_mode": file_mode,
"no_link": is_no_link(no_link, fi),
}
if file_info.get("file_type") == "hardlink":
inode_first_path = get_sorted_inode_first_path(files, fi, prefix)
file_info["inode_first_path"] = inode_first_path[0]
no_link = is_no_link(no_link, fi)
if no_link:
file_info["no_link"] = no_link
if prefix_placeholder and file_mode:
file_info["prefix_placeholder"] = prefix_placeholder
file_info["file_mode"] = file_mode
if file_info.get("file_type") == "hardlink" and os.stat(fi).st_nlink > 1:
inode_paths = get_inode_paths(files, fi, prefix)
file_info["inode_paths"] = inode_paths
files_json.append(file_info)
return files_json

Expand Down
22 changes: 9 additions & 13 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,12 @@ def test_create_info_files_json(testing_workdir, test_metadata):
build.create_info_files_json(test_metadata, info_dir, testing_workdir, files, files_with_prefix)
files_json_path = os.path.join(info_dir, "files.json")
expected_output = {
"files": [{"file_mode": None, "no_link": None, "file_type": "regular", "short_path": "one",
"prefix_placeholder": None,
"files": [{"file_type": "hardlink", "short_path": "one",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"size_in_bytes": 0},
{"file_mode": None, "no_link": None, "file_type": "regular", "short_path": "two",
"prefix_placeholder": None, "size_in_bytes": 0,
{"file_type": "hardlink", "short_path": "two", "size_in_bytes": 0,
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
{"file_mode": "text", "no_link": None, "file_type": "regular",
{"file_mode": "text", "file_type": "hardlink",
"short_path": "foo", "prefix_placeholder": "prefix/path",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"size_in_bytes": 0}],
Expand Down Expand Up @@ -256,19 +254,17 @@ def test_create_info_files_json_no_inodes(testing_workdir, test_metadata):
build.create_info_files_json(test_metadata, info_dir, testing_workdir, files, files_with_prefix)
files_json_path = os.path.join(info_dir, "files.json")
expected_output = {
"files": [{"inode_first_path": "one", "file_mode": None, "no_link": None,
"file_type": "hardlink", "short_path": "one", "prefix_placeholder": None,
"files": [{"inode_paths": ["one", "one_hl"], "file_type": "hardlink", "short_path": "one",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"size_in_bytes": 0},
{"file_mode": None, "no_link": None, "file_type": "regular", "short_path": "two",
"prefix_placeholder": None, "size_in_bytes": 0,
{"file_type": "hardlink", "short_path": "two", "size_in_bytes": 0,
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
{"inode_first_path": "one", "file_mode": None, "no_link": None,
"file_type": "hardlink", "short_path": "one_hl", "prefix_placeholder": None,
{"inode_paths": ["one", "one_hl"], "file_type": "hardlink",
"short_path": "one_hl",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"size_in_bytes": 0},
{"file_mode": "text", "no_link": None, "file_type": "regular",
"short_path": "foo", "prefix_placeholder": "prefix/path",
{"file_mode": "text", "file_type": "hardlink", "short_path": "foo",
"prefix_placeholder": "prefix/path",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"size_in_bytes": 0}],
"fields": ["short_path", "sha256", "size_in_bytes", "file_type", "file_mode",
Expand Down

0 comments on commit 3a225a3

Please sign in to comment.