mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
system: add temporary workaround for getdirinfo() issue
Fixes #670 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+20
-1
@@ -39,11 +39,30 @@ class System(object):
|
||||
def reflink(source, link_name):
|
||||
return reflink.reflink(source, link_name)
|
||||
|
||||
# FIXME
|
||||
# Temporary fix while waiting for the PR to be merged and released:
|
||||
# https://github.com/sunshowers/ntfs/pull/11
|
||||
@staticmethod
|
||||
def getdirinfo(path):
|
||||
from ntfsutils.fs import FILE_FLAG_BACKUP_SEMANTICS, FILE_SHARE_READ, OPEN_EXISTING
|
||||
from ntfsutils.fs import CreateFile, WinError, BY_HANDLE_FILE_INFORMATION
|
||||
from ntfsutils.fs import GetFileInformationByHandle, CloseHandle
|
||||
flags = FILE_FLAG_BACKUP_SEMANTICS
|
||||
hfile = CreateFile(path, 0, FILE_SHARE_READ, None, OPEN_EXISTING, flags, None)
|
||||
if hfile is None:
|
||||
raise WinError()
|
||||
info = BY_HANDLE_FILE_INFORMATION()
|
||||
rv = GetFileInformationByHandle(hfile, info)
|
||||
CloseHandle(hfile)
|
||||
if rv == 0:
|
||||
raise WinError()
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def inode(path):
|
||||
if System.is_unix():
|
||||
return os.stat(path).st_ino
|
||||
|
||||
# getdirinfo from ntfsutils works on both files and dirs
|
||||
info = getdirinfo(path)
|
||||
info = System.getdirinfo(path)
|
||||
return hash((info.dwVolumeSerialNumber, info.nFileIndexHigh, info.nFileIndexLow))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from dvc.system import System
|
||||
from tests.basic_env import TestDir
|
||||
|
||||
|
||||
class TestSystem(TestDir):
|
||||
def test_getdirinfo(self):
|
||||
if os.name != 'nt':
|
||||
return
|
||||
|
||||
# simulate someone holding an exclussive access
|
||||
locked = 'locked'
|
||||
fd = os.open(locked, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
|
||||
|
||||
# should not raise WinError
|
||||
info = System.getdirinfo(locked)
|
||||
|
||||
os.close(fd)
|
||||
Reference in New Issue
Block a user