mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
More reliable file copy behaviour - handle directory symlinks better, too
This commit is contained in:
parent
d3a0603a7b
commit
1d86d604b2
@ -2504,8 +2504,12 @@ def CopyFile(dstfile, srcfile):
|
|||||||
if NeedsBuild([dstfile], [srcfile]):
|
if NeedsBuild([dstfile], [srcfile]):
|
||||||
if os.path.islink(srcfile):
|
if os.path.islink(srcfile):
|
||||||
# Preserve symlinks
|
# Preserve symlinks
|
||||||
if os.path.exists(dstfile):
|
if os.path.isfile(dstfile) or os.path.islink(dstfile):
|
||||||
|
print("Removing file %s" % (dstfile))
|
||||||
os.unlink(dstfile)
|
os.unlink(dstfile)
|
||||||
|
elif os.path.isdir(dstfile):
|
||||||
|
print("Removing directory %s" % (dstfile))
|
||||||
|
shutil.rmtree(dstfile)
|
||||||
os.symlink(os.readlink(srcfile), dstfile)
|
os.symlink(os.readlink(srcfile), dstfile)
|
||||||
else:
|
else:
|
||||||
WriteBinaryFile(dstfile, ReadBinaryFile(srcfile))
|
WriteBinaryFile(dstfile, ReadBinaryFile(srcfile))
|
||||||
@ -2536,24 +2540,37 @@ def CopyAllJavaSources(dir, skip=[]):
|
|||||||
JustBuilt([dstfile], [srcfile])
|
JustBuilt([dstfile], [srcfile])
|
||||||
|
|
||||||
def CopyTree(dstdir, srcdir, omitVCS=True):
|
def CopyTree(dstdir, srcdir, omitVCS=True):
|
||||||
if (os.path.isdir(dstdir)):
|
if os.path.isdir(dstdir):
|
||||||
for entry in os.listdir(srcdir):
|
source_entries = os.listdir(srcdir)
|
||||||
|
for entry in source_entries:
|
||||||
srcpth = os.path.join(srcdir, entry)
|
srcpth = os.path.join(srcdir, entry)
|
||||||
dstpth = os.path.join(dstdir, entry)
|
dstpth = os.path.join(dstdir, entry)
|
||||||
if (os.path.isfile(srcpth)):
|
|
||||||
|
if os.path.islink(srcpth) or os.path.isfile(srcpth):
|
||||||
if not omitVCS or entry not in VCS_FILES:
|
if not omitVCS or entry not in VCS_FILES:
|
||||||
CopyFile(dstpth, srcpth)
|
CopyFile(dstpth, srcpth)
|
||||||
else:
|
else:
|
||||||
if not omitVCS or entry not in VCS_DIRS:
|
if not omitVCS or entry not in VCS_DIRS:
|
||||||
CopyTree(dstpth, srcpth)
|
CopyTree(dstpth, srcpth)
|
||||||
|
|
||||||
|
# Delete files in dstdir that are not in srcdir.
|
||||||
|
for entry in os.listdir(dstdir):
|
||||||
|
if entry not in source_entries:
|
||||||
|
path = os.path.join(dstdir, entry)
|
||||||
|
if os.path.islink(path) or os.path.isfile(path):
|
||||||
|
os.remove(path)
|
||||||
|
elif os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
else:
|
else:
|
||||||
if GetHost() == 'windows':
|
if GetHost() == 'windows':
|
||||||
srcdir = srcdir.replace('/', '\\')
|
srcdir = srcdir.replace('/', '\\')
|
||||||
dstdir = dstdir.replace('/', '\\')
|
dstdir = dstdir.replace('/', '\\')
|
||||||
cmd = 'xcopy /I/Y/E/Q "' + srcdir + '" "' + dstdir + '"'
|
cmd = 'xcopy /I/Y/E/Q "' + srcdir + '" "' + dstdir + '"'
|
||||||
|
oscmd(cmd)
|
||||||
else:
|
else:
|
||||||
cmd = 'cp -R -f ' + srcdir + ' ' + dstdir
|
if subprocess.call(['cp', '-R', '-f', srcdir, dstdir]) != 0:
|
||||||
oscmd(cmd)
|
exit("Copy failed.")
|
||||||
|
|
||||||
if omitVCS:
|
if omitVCS:
|
||||||
DeleteVCS(dstdir)
|
DeleteVCS(dstdir)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user