Skip to content

Commit

Permalink
Allow overwrites during rename. This is required for doing atomic puts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apteryx0 committed Jun 12, 2024
1 parent e07a8e6 commit 1c21d24
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hdfs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,19 +924,22 @@ def delete(self, hdfs_path, recursive=False, skip_trash=True):
_logger.info('%r moved to trash at %r.', hdfs_path, dst_path)
return True

def rename(self, hdfs_src_path, hdfs_dst_path):
def rename(self, hdfs_src_path, hdfs_dst_path, overwrite=False):
"""Move a file or folder.
:param hdfs_src_path: Source path.
:param hdfs_dst_path: Destination path. If the path already exists and is
a directory, the source will be moved into it. If the path exists and is
a file, or if a parent destination directory is missing, this method will
raise an :class:`HdfsError`.
:param overwrite: overwrite the hdfs_dst_path if it already exists, rather
than raising an :class:`HdfsError`.
"""
_logger.info('Renaming %r to %r.', hdfs_src_path, hdfs_dst_path)
hdfs_dst_path = self.resolve(hdfs_dst_path)
res = self._rename(hdfs_src_path, destination=hdfs_dst_path)
kwargs = {"renameoptions": "overwrite"} if overwrite else {}
res = self._rename(hdfs_src_path, destination=hdfs_dst_path, **kwargs)
if not res.json()['boolean']:
raise HdfsError(
'Unable to rename %r to %r.',
Expand Down

0 comments on commit 1c21d24

Please sign in to comment.