Hallo,
was passiert wenn während eines Ausschneidevorgangs mit dem Python Befehl: shutil.move(src,dst)
die Verbindung zwischen 2 Rechnern, oder in einem Netzwerk getrennt wird.
Wird die Quelldatei erst nach dem Kopiervorgang(vollständig) gelöscht, oder wird die Quelldate dabei so beschädigt, so dass ein erneuter Kopiervorgang nicht möglich ist?
Vielen Dank für Hinweise,
Kreavis
Ausschneiden shutil.move(src,dst), Verbindung trennen
- Defnull
- User
- Beiträge: 778
- Registriert: Donnerstag 18. Juni 2009, 22:09
- Wohnort: Göttingen
- Kontaktdaten:
"If the destination is on the current filesystem, then simply use rename. Otherwise, copy src (with copy2()) to the dst and then remove src."
Bottle: Micro Web Framework + Development Blog
Das habe ich auch gelesen, hab mich aber nicht auf mein Problem angesprochen gefühlt. Aber dann wird das wohl die "Anleitung sein". Also erst kopieren und dann entfernen. So hätte ich es als workaround umgesetzt. Dann mach ich das jetzt mal so.
Danke
Danke
War es jetzt so schwierig, sich bei Unklarheiten den Quellcode anzugucken?
Code: Alles auswählen
def move(src, dst):
"""Recursively move a file or directory to another location. This is
similar to the Unix "mv" command.
If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If the destination already exists but is not a directory, it may be
overwritten depending on os.rename() semantics.
If the destination is on our current filesystem, then rename() is used.
Otherwise, src is copied to the destination and then removed.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.
"""
real_dst = dst
if os.path.isdir(dst):
real_dst = os.path.join(dst, _basename(src))
if os.path.exists(real_dst):
raise Error, "Destination path '%s' already exists" % real_dst
try:
os.rename(src, real_dst)
except OSError:
if os.path.isdir(src):
if destinsrc(src, dst):
raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
copytree(src, real_dst, symlinks=True)
rmtree(src)
else:
copy2(src, real_dst)
os.unlink(src)