Differences between revisions 9 and 12 (spanning 3 versions)
Revision 9 as of 2010-12-02 23:22:07
Size: 1343
Editor: abuehl
Comment:
Revision 12 as of 2010-12-11 19:03:46
Size: 1593
Editor: abuehl
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
If the file f has been opened for reading by another process using Python's '`open(f)`',
then '`os.unlink(f)`' will raise
If the file f itself or ''any hardlinked copy of f'' has been opened for reading by another
process using Python's '`open()`', then '`os.unlink(f)`' will raise
Line 37: Line 37:
 * Bts:issue2543: "os.unlink deletes wrong file on windows share served by Samba"
 * [[http://mercurial.markmail.org/thread/t5ecar6sn3ekifo6|How Mercurial could be made working with Virus Scanners on Windows]]

Unlinking Files on Windows

/!\ This page is intended for developers.

This page describes what happens when Python's 'os.unlink(f)' is called on Windows.

1. File opened using Python's "open"

If the file f itself or any hardlinked copy of f has been opened for reading by another process using Python's 'open()', then 'os.unlink(f)' will raise

WindowsError: [Error 32] The process cannot access the file because it is being
used by another process: <f>

2. File opened using Mercurial's "posixfile"

If the file f has been opened for reading by another process with 'posixfile(f)', calling unlink will send that file into a "scheduled delete" state.

Scheduled delete has the following characteristics:

  • (a) the entry in the directory for f is still kept
  • (b) calling 'fd = posixfile(f, 'w')' will raise 'IOError: [Errno 13] <f>: Access is denied'

  • (c) calling 'os.rename(f, f+'.foo')' will raise 'WindowsError: [Error 5] Access is denied'

  • (d) calling 'os.lstat(f)' will raise 'WindowsError: [Error 5] Access is denied: <f>'

  • (e) calling 'os.path.exists(f)' returns False

Scheduled delete is left as soon as the other process closes the file.

3. See also


CategoryInternals

UnlinkingFilesOnWindows (last edited 2017-09-02 08:00:32 by abuehl)