forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dvc.objects: move hashing functions to dvc.objects
This commit moves `HashedStreamReader`/`get_hash_file`/`file_md5` into `dvc.objects.hash`. The `get_hash_file` has been renamed to `hash_file`. This also copies `relpath` and `is_exec` to the `dvc.fs.utils`.
- Loading branch information
Showing
25 changed files
with
257 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import stat | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .base import AnyFSPath | ||
|
||
|
||
def is_exec(mode: int) -> bool: | ||
return bool(mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) | ||
|
||
|
||
def relpath(path: "AnyFSPath", start: "AnyFSPath" = os.curdir) -> "AnyFSPath": | ||
path = os.fspath(path) | ||
start = os.path.abspath(os.fspath(start)) | ||
|
||
# Windows path on different drive than curdir doesn't have relpath | ||
if os.name == "nt": | ||
# Since python 3.8 os.realpath resolves network shares to their UNC | ||
# path. So, to be certain that relative paths correctly captured, | ||
# we need to resolve to UNC path first. We resolve only the drive | ||
# name so that we don't follow any 'real' symlinks on the path | ||
def resolve_network_drive_windows(path_to_resolve): | ||
drive, tail = os.path.splitdrive(path_to_resolve) | ||
return os.path.join(os.path.realpath(drive), tail) | ||
|
||
path = resolve_network_drive_windows(os.path.abspath(path)) | ||
start = resolve_network_drive_windows(start) | ||
if not os.path.commonprefix([start, path]): | ||
return path | ||
return os.path.relpath(path, start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.