This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients draghuram, facundobatista, gvanrossum, init, pitrou
Date 2008-01-23.21:28:19
SpamBayes Score 0.042032305
Marked as misclassified No
Message-id <ca471dc20801231328i490a282dtf55914c4b326ffca@mail.gmail.com>
In-reply-to <1201099585.88.0.373241749138.issue1577@psf.upfronthosting.co.za>
Content
> Before tackling this, I'd like a precision on os.rename(src, dst)
> semantics. The documentation says "If dst is a directory, OSError will
> be raised". However, under Linux, if src is a directory and dst is an
> empty directory, dst is overwritten with src:
>
> $ mkdir src dst
> $ touch dst/t
> $ ./python -c "import os; os.rename('src', 'dst')"
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> OSError: [Errno 39] Directory not empty
> $ rm dst/t
> $ ./python -c "import os; os.rename('src', 'dst')"
> $
>
> Is this a bug, a misfeature, or just an imprecision in the documentation?

To be honest, I wasn't aware of this behavior of the rename() system
call for directories on Unix. It is most certainly a feature (of the
system call) that should be maintained (for the system call wrapper).

shutil.move() should not mimic this though -- it should more closely
approximate the "mv" utility's behavior, which doesn't differentiate
between empty and non-empty destination directories, and always moves
*into* the target when it is a directory (and complains if the
resulting destination path already exists).
History
Date User Action Args
2008-01-23 21:28:22gvanrossumsetspambayes_score: 0.0420323 -> 0.042032305
recipients: + gvanrossum, facundobatista, pitrou, draghuram, init
2008-01-23 21:28:20gvanrossumlinkissue1577 messages
2008-01-23 21:28:19gvanrossumcreate