Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e4a3dc

Browse files
author
Éric Araujo
committed
Ignore .nfs* files in distutils (#7719).
These files are created by some NFS clients a file is edited and removed concurrently (see added link in doc for more info). If such a file is removed between distutils calls listdir and copy, it will get confused. Other special files are ignored in sdist (namely VCS directories), but this has to be filtered out earlier.
1 parent 09974b4 commit 3e4a3dc

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

Doc/distutils/apiref.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,12 @@ directories.
992992
destination of the symlink will be copied. *update* and *verbose* are the same
993993
as for :func:`copy_file`.
994994

995+
Files in *src* that begin with :file:`.nfs` are skipped (more information on
996+
these files is available in answer D2 of the `NFS FAQ page
997+
<http://nfs.sourceforge.net/#section_d>`_.
998+
999+
.. versionchanged:: 3.2.4
1000+
NFS files are ignored.
9951001

9961002
.. function:: remove_tree(directory[, verbose=0, dry_run=0])
9971003

Lib/distutils/dir_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
141141
src_name = os.path.join(src, n)
142142
dst_name = os.path.join(dst, n)
143143

144+
if n.startswith('.nfs'):
145+
# skip NFS rename files
146+
continue
147+
144148
if preserve_symlinks and os.path.islink(src_name):
145149
link_dest = os.readlink(src_name)
146150
if verbose >= 1:

Lib/distutils/tests/test_dir_util.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def test_create_tree_verbosity(self):
7676

7777
remove_tree(self.root_target, verbose=0)
7878

79-
8079
def test_copy_tree_verbosity(self):
8180

8281
mkpath(self.target, verbose=0)
@@ -88,11 +87,8 @@ def test_copy_tree_verbosity(self):
8887

8988
mkpath(self.target, verbose=0)
9089
a_file = os.path.join(self.target, 'ok.txt')
91-
f = open(a_file, 'w')
92-
try:
90+
with open(a_file, 'w') as f:
9391
f.write('some content')
94-
finally:
95-
f.close()
9692

9793
wanted = ['copying %s -> %s' % (a_file, self.target2)]
9894
copy_tree(self.target, self.target2, verbose=1)
@@ -101,6 +97,21 @@ def test_copy_tree_verbosity(self):
10197
remove_tree(self.root_target, verbose=0)
10298
remove_tree(self.target2, verbose=0)
10399

100+
def test_copy_tree_skips_nfs_temp_files(self):
101+
mkpath(self.target, verbose=0)
102+
103+
a_file = os.path.join(self.target, 'ok.txt')
104+
nfs_file = os.path.join(self.target, '.nfs123abc')
105+
for f in a_file, nfs_file:
106+
with open(f, 'w') as fh:
107+
fh.write('some content')
108+
109+
copy_tree(self.target, self.target2)
110+
self.assertEqual(os.listdir(self.target2), ['ok.txt'])
111+
112+
remove_tree(self.root_target, verbose=0)
113+
remove_tree(self.target2, verbose=0)
114+
104115
def test_ensure_relative(self):
105116
if os.sep == '/':
106117
self.assertEqual(ensure_relative('/home/foo'), 'home/foo')

Lib/distutils/tests/test_sdist.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ def get_cmd(self, metadata=None):
8383

8484
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
8585
def test_prune_file_list(self):
86-
# this test creates a package with some vcs dirs in it
87-
# and launch sdist to make sure they get pruned
88-
# on all systems
86+
# this test creates a project with some VCS dirs and an NFS rename
87+
# file, then launches sdist to check they get pruned on all systems
8988

9089
# creating VCS directories with some files in them
9190
os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
@@ -99,6 +98,8 @@ def test_prune_file_list(self):
9998
self.write_file((self.tmp_dir, 'somecode', '.git',
10099
'ok'), 'xxx')
101100

101+
self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx')
102+
102103
# now building a sdist
103104
dist, cmd = self.get_cmd()
104105

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ Library
177177

178178
- Issue #16628: Fix a memory leak in ctypes.resize().
179179

180+
- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later
181+
on. Initial patch by SilentGhost and Jeff Ramnani.
182+
180183
- Issue #13120: Allow to call pdb.set_trace() from thread.
181184
Patch by Ilya Sandler.
182185

0 commit comments

Comments
 (0)