Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: handle long filenames #5201

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dvc/tree/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def move(self, from_info, to_info, mode=None):
move(from_info, to_info, mode=mode)

def copy(self, from_info, to_info):
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed helpful before to keep the relation between the original file name and this temp file if something goes wrong, but in reality the data is already in cache at this point so it would be helpful to just provide intructions/mechanism to recover it. Aaand we delete this temp file anyway down below πŸ™‚

try:
System.copy(from_info, tmp_info)
os.chmod(tmp_info, self.file_mode)
Expand All @@ -185,7 +185,7 @@ def copy(self, from_info, to_info):

def copy_fobj(self, fobj, to_info):
self.makedirs(to_info.parent)
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
try:
copy_fobj_to_file(fobj, tmp_info)
os.chmod(tmp_info, self.file_mode)
Expand Down Expand Up @@ -229,7 +229,7 @@ def is_hardlink(path_info):
return System.is_hardlink(path_info)

def reflink(self, from_info, to_info):
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
System.reflink(from_info, tmp_info)
# NOTE: reflink has its own separate inode, so you can set permissions
# that are different from the source.
Expand Down
19 changes: 19 additions & 0 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import filecmp
import logging
import os
Expand Down Expand Up @@ -972,3 +973,21 @@ def test_add_preserve_meta(tmp_dir, dvc):
meta: some metadata
"""
)


# NOTE: unless long paths are enabled on Windows, PATH_MAX and NAME_MAX
# are the same 260 chars, which makes the test unnecessarily complex
@pytest.mark.skipif(os.name == "nt", reason="unsupported on Windows")
def test_add_long_fname(tmp_dir, dvc):
name_max = os.pathconf(tmp_dir, "PC_NAME_MAX")
name = "a" * name_max
tmp_dir.gen({"data": {name: "foo"}})

# nothing we can do in this case, as the resulting dvcfile
# will definitely exceed NAME_MAX
with pytest.raises(OSError) as info:
dvc.add(os.path.join("data", name))
assert info.value.errno == errno.ENAMETOOLONG

dvc.add("data")
assert (tmp_dir / "data").read_text() == {name: "foo"}