From b39345e1f0aab3e034491d72111533a6491b1e90 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Tue, 28 Jan 2020 21:50:27 +0000 Subject: [PATCH] Use shutil.move() instead of os.replace/rename Signed-off-by: JoeLametta --- whipper/common/renamer.py | 5 +++-- whipper/program/cdparanoia.py | 2 +- whipper/test/test_common_program.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/whipper/common/renamer.py b/whipper/common/renamer.py index 941b018..9cf6b0a 100644 --- a/whipper/common/renamer.py +++ b/whipper/common/renamer.py @@ -19,6 +19,7 @@ # along with whipper. If not, see . import os +import shutil import tempfile """Rename files on file system and inside metafiles in a resumable way.""" @@ -168,7 +169,7 @@ class RenameFile(Operation): assert not os.path.exists(self._destination) def do(self): - os.rename(self._source, self._destination) + shutil.move(self._source, self._destination) def serialize(self): return '"%s" "%s"' % (self._source, self._destination) @@ -203,7 +204,7 @@ class RenameInFile(Operation): s.replace(self._source, self._destination).encode()) os.close(fd) - os.rename(name, self._path) + shutil.move(name, self._path) def serialize(self): return '"%s" "%s" "%s"' % (self._path, self._source, self._destination) diff --git a/whipper/program/cdparanoia.py b/whipper/program/cdparanoia.py index d410d0c..79d8a40 100644 --- a/whipper/program/cdparanoia.py +++ b/whipper/program/cdparanoia.py @@ -535,7 +535,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask): if not self.exception: try: logger.debug('moving to final path %r', self.path) - os.rename(self._tmppath, self.path) + shutil.move(self._tmppath, self.path) # FIXME: catching too general exception (Exception) except Exception as e: logger.debug('exception while moving to final ' diff --git a/whipper/test/test_common_program.py b/whipper/test/test_common_program.py index 8871de9..7856f55 100644 --- a/whipper/test/test_common_program.py +++ b/whipper/test/test_common_program.py @@ -3,6 +3,7 @@ import os +import shutil import unittest from tempfile import NamedTemporaryFile @@ -80,7 +81,7 @@ class CoverArtTestCase(unittest.TestCase): with NamedTemporaryFile(suffix='.cover.jpg', delete=False) as f: f.write(data) os.chmod(f.name, 0o644) - os.replace(f.name, cover_art_path) + shutil.move(f.name, cover_art_path) return cover_art_path def testCoverArtPath(self):