From 61996dbefc40530a77522893e406dde5d60bad0e Mon Sep 17 00:00:00 2001 From: yyyyuki Date: Fri, 22 Nov 2024 15:26:19 +0900 Subject: [PATCH] replace os.rename with os.replace --- luigi/contrib/ftp.py | 2 +- luigi/contrib/ssh.py | 2 +- luigi/local_target.py | 6 +++--- test/local_target_test.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/luigi/contrib/ftp.py b/luigi/contrib/ftp.py index d155e8ef8b..78a423704e 100644 --- a/luigi/contrib/ftp.py +++ b/luigi/contrib/ftp.py @@ -309,7 +309,7 @@ def get(self, path, local_path): self._close() - os.rename(tmp_local_path, local_path) + os.replace(tmp_local_path, local_path) def _sftp_get(self, path, tmp_local_path): self.conn.get(path, tmp_local_path) diff --git a/luigi/contrib/ssh.py b/luigi/contrib/ssh.py index beda1c9e23..9e7ee03821 100644 --- a/luigi/contrib/ssh.py +++ b/luigi/contrib/ssh.py @@ -270,7 +270,7 @@ def get(self, path, local_path): tmp_local_path = local_path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000) self._scp("%s:%s" % (self.remote_context._host_ref(), path), tmp_local_path) - os.rename(tmp_local_path, local_path) + os.replace(tmp_local_path, local_path) class AtomicRemoteFileWriter(luigi.format.OutputPipeProcessWrapper): diff --git a/luigi/local_target.py b/luigi/local_target.py index 5cdade2ec7..ec6ae78023 100644 --- a/luigi/local_target.py +++ b/luigi/local_target.py @@ -37,7 +37,7 @@ class atomic_file(AtomicLocalFile): """ def move_to_final_destination(self): - os.rename(self.tmp_path, self.path) + os.replace(self.tmp_path, self.path) def generate_tmp_path(self, path): return path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000) @@ -109,12 +109,12 @@ def move(self, old_path, new_path, raise_if_exists=False): if d and not os.path.exists(d): self.mkdir(d) try: - os.rename(old_path, new_path) + os.replace(old_path, new_path) except OSError as err: if err.errno == errno.EXDEV: new_path_tmp = '%s-%09d' % (new_path, random.randint(0, 999999999)) shutil.copy(old_path, new_path_tmp) - os.rename(new_path_tmp, new_path) + os.replace(new_path_tmp, new_path) os.remove(old_path) else: raise err diff --git a/test/local_target_test.py b/test/local_target_test.py index d9c78539c5..1193d67d6f 100644 --- a/test/local_target_test.py +++ b/test/local_target_test.py @@ -152,16 +152,16 @@ def rename_across_filesystems(src, dst): err.errno = EXDEV raise err - real_rename = os.rename + real_rename = os.replace - def mockrename(src, dst): + def mockreplace(src, dst): if '-across-fs' in src: real_rename(src, dst) else: rename_across_filesystems(src, dst) copy = '%s-across-fs' % self.copy - with mock.patch('os.rename', mockrename): + with mock.patch('os.replace', mockreplace): t.move(copy) self.assertFalse(os.path.exists(self.path))