Ausschneiden shutil.move(src,dst), Verbindung trennen

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Kreavis
User
Beiträge: 11
Registriert: Dienstag 11. August 2009, 11:15

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
Benutzeravatar
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
Kreavis
User
Beiträge: 11
Registriert: Dienstag 11. August 2009, 11:15

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
Benutzeravatar
snafu
User
Beiträge: 6740
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

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)
Antworten