Skip to content

Commit

Permalink
system: remove legacy code (iterative#6685)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop authored Sep 25, 2021
1 parent bdaf4ac commit 6d6a3f1
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 113 deletions.
3 changes: 1 addition & 2 deletions dvc/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from dvc.path_info import PathInfo
from dvc.pathspec_math import PatternInfo, merge_patterns
from dvc.scheme import Schemes
from dvc.system import System
from dvc.types import AnyPath, List, Optional
from dvc.utils import relpath
from dvc.utils.collections import PathStringTrie
Expand Down Expand Up @@ -84,7 +83,7 @@ def _get_normalize_path(self, dirname, basename):
else:
return False

if not System.is_unix():
if os.name == "nt":
path = normalize_file(path)
return path

Expand Down
95 changes: 3 additions & 92 deletions dvc/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@


class System:
@staticmethod
def is_unix():
return os.name != "nt"

@staticmethod
def hardlink(source, link_name):
try:
Expand Down Expand Up @@ -117,99 +113,14 @@ def reflink(source, link_name):
# so we need to chmod it to look like a normal copy.
os.chmod(link_name, 0o666 & ~umask)

@staticmethod
def _getdirinfo(path):
from collections import namedtuple

from win32file import ( # pylint: disable=import-error
FILE_FLAG_BACKUP_SEMANTICS,
FILE_FLAG_OPEN_REPARSE_POINT,
FILE_SHARE_READ,
OPEN_EXISTING,
CreateFileW,
GetFileInformationByHandle,
)

# NOTE: use FILE_FLAG_OPEN_REPARSE_POINT to open symlink itself and not
# the target See https://docs.microsoft.com/en-us/windows/desktop/api/
# fileapi/nf-fileapi-createfilew#symbolic-link-behavior
flags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT

hfile = CreateFileW(
path, 0, FILE_SHARE_READ, None, OPEN_EXISTING, flags, None
)

# See BY_HANDLE_FILE_INFORMATION structure from fileapi.h
Info = namedtuple(
"BY_HANDLE_FILE_INFORMATION",
[
"dwFileAttributes",
"ftCreationTime",
"ftLastAccessTime",
"ftLastWriteTime",
"dwVolumeSerialNumber",
"nFileSizeHigh",
"nFileSizeLow",
"nNumberOfLinks",
"nFileIndexHigh",
"nFileIndexLow",
],
)

return Info(*GetFileInformationByHandle(hfile))

@staticmethod
def inode(path):
path = os.fspath(path)

if System.is_unix():
import ctypes

inode = os.lstat(path).st_ino
# NOTE: See https://bugs.python.org/issue29619 and
# https://stackoverflow.com/questions/34643289/
# pythons-os-stat-is-returning-wrong-inode-value
inode = ctypes.c_ulong(inode).value
else:
# getdirinfo from ntfsutils works on both files and dirs
info = System._getdirinfo(path)
inode = abs(
hash(
(
info.dwVolumeSerialNumber,
info.nFileIndexHigh,
info.nFileIndexLow,
)
)
)
assert inode >= 0
assert inode < 2 ** 64
return inode
return os.lstat(path).st_ino

@staticmethod
def is_symlink(path):
path = os.fspath(path)

if System.is_unix():
return os.path.islink(path)

# https://docs.microsoft.com/en-us/windows/desktop/fileio/
# file-attribute-constants
from winnt import ( # pylint: disable=import-error
FILE_ATTRIBUTE_REPARSE_POINT,
)

if os.path.lexists(path):
info = System._getdirinfo(path)
return info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT
return False
return os.path.islink(path)

@staticmethod
def is_hardlink(path):
path = os.fspath(path)

if System.is_unix():
return os.stat(path).st_nlink > 1

info = System._getdirinfo(path)
return info.nNumberOfLinks > 1
return os.stat(path).st_nlink > 1
1 change: 0 additions & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ packaging>=19.0
zc.lockfile>=1.2.1
flufl.lock>=3.2,<4
win-unicode-console>=0.5; sys_platform == 'win32'
pywin32>=225; sys_platform == 'win32' and python_version < '3.10'
networkx>=2.5
psutil>=5.8.0
pydot>=1.2.4
Expand Down
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ google-compute-engine==2.8.13
google-cloud-storage==1.42.1
urllib3==1.26.6
dvclive>=0.2.1
pywin32>=225; sys_platform == 'win32' and python_version < '3.10'

# required by collective.checkdocs
Pygments==2.10.0
Expand Down
1 change: 0 additions & 1 deletion scripts/pyinstaller/hooks/hook-win32file.py

This file was deleted.

17 changes: 0 additions & 17 deletions tests/func/test_system.py

This file was deleted.

0 comments on commit 6d6a3f1

Please sign in to comment.