o a @sHdZddlZddlZddlmZddlmZdgZddZd d dZ dS) z Move a file in the safest way possible:: >>> from django.core.files.move import file_move_safe >>> file_move_safe("/tmp/old_file", "/tmp/new_file") N)copystat)locksfile_move_safecCsZttjdrztj||WStyYdSwtjtj|tjtj|kS)NsamefileF)hasattrospathrOSErrornormcaseabspath)srcdstr8/usr/lib/python3/dist-packages/django/core/files/move.py _samefiles  rFc Cst||rdSz|st|tjrtd|t||WdSty(Ynwt|dS}t|tjtj Bt tddB|sBtj ndB}z(t |t jd}|dkrc||}t|||dksTWt |t|n t |t|wWdn1swYzt||Wnty}z |jtjkrWYd}~nd}~wwzt|WdSty}zt |dddkrÂWYd}~dSd}~ww) aU Move a file from one location to another in the safest way possible. First, try ``os.rename``, which is simple but will break across filesystems. If that fails, stream manually from one file to another in pure Python. If the destination file exists and ``allow_overwrite`` is ``False``, raise ``FileExistsError``. Nz8Destination file %s exists and allow_overwrite is False.rbO_BINARYrwinerror )rraccessF_OKFileExistsErrorrenamer openO_WRONLYO_CREATgetattrO_EXCLrlockLOCK_EXreadwriteunlockcloserPermissionErrorerrnoEPERMremove) old_file_name new_file_name chunk_sizeallow_overwriteold_filefd current_chunkerrrrsV             )rF) __doc__r'rshutilrdjango.core.filesr__all__rrrrrrs