Skip to content

Commit

Permalink
add: handle long filenames (#5201) (#5206)
Browse files Browse the repository at this point in the history
(cherry picked from commit b779a11)

Co-authored-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
mergify[bot] and efiop authored Jan 5, 2021
1 parent 4bca30e commit c5fd3e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dvc/tree/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,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("")
try:
System.copy(from_info, tmp_info)
os.chmod(tmp_info, self.file_mode)
Expand All @@ -188,7 +188,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 @@ -236,7 +236,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 @@ -951,3 +952,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"}

0 comments on commit c5fd3e3

Please sign in to comment.