
    3j                     j    S SK Jr  S SKrS SKrS SKrS SKJrJr  S SKJ	r	  S	S jr
S
S jrSS jr/ SQrg)    )annotationsN)EACCESEISDIR)Pathc                    [         R                  " U 5      nUR                  S:w  a  UR                  [        R
                  -  (       d  [        [        SU 5      e[        R                  " UR                  5      (       a6  [        R                  S:X  a  [        [        SU 5      e[        [        SU 5      egg! [         a     gf = f)a  
Raise an exception if attempting to open the file for writing would fail.

This is done so files that will never be writable can be separated from files that are writable but currently
locked.

:param filename: file to check

:raises OSError: as if the file was opened for writing.

Nr   zPermission deniedwin32zIs a directory)osstatOSErrorst_mtimest_modeS_IWUSRPermissionErrorr   S_ISDIRsysplatformIsADirectoryErrorr   )filename	file_stats     H/home/wildlama/miniconda3/lib/python3.13/site-packages/filelock/_util.pyraise_on_not_writable_filer   
   s    GGH%	 Q!!DLL0!&*=xHH<<	))**||w&%f.A8LL (0@(KK +	   s   B8 8
CCc                J    [        U 5      R                  R                  SSS9  g)zd
Ensure the directory containing the file exists (create it if necessary).

:param filename: file.

T)parentsexist_okN)r   parentmkdir)r   s    r   ensure_directory_existsr   (   s!     	Nt<    c                .   U  S[         R                  " 5        3n[        U 5      R                  U5         [         R                  " U5      nUR                  U:  d  UR                  U:w  a  g[        U5      R                  5         g! [
         a     gf = f)us  
Atomically break a stale lock file that was judged stale at modification time *mtime_before*.

The file is renamed to a process-private name before being unlinked, so two processes breaking the same lock
cannot delete each other's work (only one rename of a given inode succeeds; the loser gets ``OSError``). After the
rename the file is re-checked: a newer modification time, or a different inode than *ino_before*, means a peer
recreated the lock between the stale decision and the rename, so we grabbed a live file and must abort, leaving the
renamed file in place rather than rolling back (a rollback rename is itself racy — same trade-off as the soft
read/write marker break). The inode check matters because filesystems with coarse modification-time granularity
(NFS, FAT) can give a same-second recreation the old mtime, so mtime alone would not catch it and a live lock would
be unlinked; the inode is the reliable identity, mirroring the token re-check in the soft read/write marker break.
``lstat`` is used so a hostile symlink swapped in after the decision is not followed.

:param lock_file: path to the lock file to break.
:param mtime_before: modification time observed when the lock was judged stale.
:param ino_before: inode number observed when the lock was judged stale.

:raises OSError: if the rename fails (e.g. the file vanished or is not owned in a sticky directory).

z.break.N)	r	   getpidr   renamelstatr   r   st_inounlink)	lock_filemtime_before
ino_before
break_pathst_afters        r   break_lock_filer*   2   s    * ;gbiik]3JO:&88J' <'8??j+H	  s   B 
BB)r*   r   r   )r   strreturnNone)r   z
Path | strr,   r-   )r%   r+   r&   floatr'   intr,   r-   )
__future__r   r	   r
   r   errnor   r   pathlibr   r   r   r*   __all__ r   r   <module>r5      s/    " 	  
   L<=@r   