Re[2]: блокировка файла без его открытия
От: Аноним  
Дата: 07.04.09 08:11
Оценка:
DB>я что-то не понимаю, зачем гадать, если в мсдн все написано:

DB>

DB>If the call to LockFile completes synchronously, a completion entry may not be queued when a completion port is associated with the file handle.

DB>The UnlockFile function unlocks a file region locked by LockFile.

DB>Locking a region of a file gives the threads of the locking process exclusive access to the specified region using this file handle. If the file handle is inherited by a process created by the locking process, the child process is not granted access to the locked region. If the locking process opens the file a second time, it cannot access the specified region through this second handle until it unlocks the region.

DB>Locking a region of a file does not prevent reading from a mapped file view.

DB>You can lock bytes that are beyond the end of the current file. This is useful to coordinate adding records to the end of a file.

DB>Locks may not overlap an existing locked region of the file.

DB>If LockFile cannot lock a region of a file, it returns zero immediately. It does not block. To issue a file lock request that will block until the lock is acquired, use LockFileEx without LOCKFILE_FAIL_IMMEDIATELY.

DB>If a process terminates with a portion of a file locked or closes a file that has outstanding locks, the locks are unlocked by the operating system. However, the time it takes for the operating system to unlock these locks depends upon available system resources. Therefore, it is recommended that your process explicitly unlock all files it has locked when it terminates. If this is not done, access to these files may be denied if the operating system has not yet unlocked them.


Проверил. Не катит.

Происходит следующее...
У меня есть два файла: file.dll и file.dll.tmp
При проверке этих файлов я их открываю и на каждый вешаю лок (хотя без лока происходит всё то же самое).
Если версия file.dll.tmp выше версии file.dll, я должен заменить file.dll на file.dll.tmp.
Функция MoveFileEx( file.dll.tmp, file.dll, MOVEFILE_REPLACE_EXISTING ) вылетает с ошибкой "Ошибка доступа"
Функция DeleteFile( file.dll ) файл не удаляет, а лишь помечает к удалению _ПОСЛЕ_ закрытия, и следовательно MoveFile опять выдаёт "Ошибку доступа".
Если перед удалением файл закрывать, упадёт блокировка.

То есть происходит именно то, о чём я писал в своём первом посте.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.