os_unix.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def rename(src, dst):
        try:
                os.rename(src, dst)
        except OSError as e:
                # Handle the case where we tried to rename a file across a
                # filesystem boundary.
                if e.errno != errno.EXDEV or not os.path.isfile(src):
                        raise

                # Copy the data and metadata into a temporary file in the same
                # filesystem as the destination, rename into place, and unlink
                # the original.
                try:
                        fd, tmpdst = tempfile.mkstemp(suffix=".pkg5.xdev",
                            dir=os.path.dirname(dst))
                except OSError as e:
                        # If we don't have sufficient permissions to put the
                        # file where we want it, then higher levels can deal
                        # with that effectively, but people will want to know
                        # the original destination filename.
                        if e.errno == errno.EACCES:
                                e.filename=dst
                        raise
                os.close(fd)
                shutil.copy2(src, tmpdst)
                os.rename(tmpdst, dst)
                os.unlink(src)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号