Check if file is on same partition, if so move it, if not copy it.

This commit is contained in:
dbr
2008-11-01 15:02:09 +10:30
parent d0663047a8
commit 6b97c26b36

View File

@@ -158,6 +158,8 @@ def does_file_exist(path):
file_exists = True
return file_exists
def same_partition(f1, f2):
return os.stat(f1).st_dev == os.stat(f2).st_dev
###########################
@@ -189,6 +191,14 @@ def main():
file_exists = does_file_exist(newfile)
if file_exists:
print "[!] File already exists, not copying"
else:
if same_partition(oldfile, newpath):
print "[* Moving file]"
try:
shutil.rename(oldfile, newpath)
except:
print "[!] Error moving file! %s" % (errormsg)
#end try
else:
print "[*] Copying file"
try:
@@ -198,6 +208,7 @@ def main():
else:
print "[*] ..done"
#end try
#end if same_partition
#end if not file_exists
else:
print "Skipping file"