-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
finalizing paths.json spec #1535
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e27aa17
Some edits to files.json
soapy1 451d571
Create NodeType and FileMode Enums
soapy1 1248ff4
Rename file_type to node_type
soapy1 ba9e4fb
Add docstring for additional enums
soapy1 436f034
Refactor NodeType
soapy1 c7f3e2f
Rename file_type method to node_type
soapy1 48f37c7
Import NodeType and FileMode from conda
soapy1 59f3b78
JSON encode node_type
soapy1 341c580
Include CrossPlatformStLink
soapy1 511a5e7
Json dump with EntityEncoder
soapy1 2dad147
Fix tests
soapy1 2e5cabf
Fix tests
soapy1 6b463cd
accurate names; pk ids sorted to top
kalefranz 7442b61
Some edits to files.json
soapy1 c4f473c
Create NodeType and FileMode Enums
soapy1 8b31403
Add docstring for additional enums
soapy1 5876d8b
Import NodeType and FileMode from conda
soapy1 5125e15
JSON encode node_type
soapy1 44c8342
Include CrossPlatformStLink
soapy1 17ac64a
Fix tests
soapy1 dbc044f
Fix tests
soapy1 dd25642
Merge branch 'master' into files-json-review
soapy1 ab51199
Add test for conda master to travis
soapy1 4af5fa3
Better messages on win errors
soapy1 de6b424
Test conda interface enums/classes
soapy1 b7d7ba3
Update travis to test against conda canary
soapy1 e67d419
Import PathType for conda instead of NodeType
soapy1 47b9136
Add test for st_nlink on win
soapy1 1689e70
Merge branch 'master' into files-json-review
soapy1 e9885a1
Skip crossplatform_st_link_on_win if not on win
soapy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import conda.config as cc # NOQA | ||
from conda.config import rc_path # NOQA | ||
from conda.version import VersionOrder # NOQA | ||
from enum import Enum | ||
|
||
import os | ||
|
||
|
@@ -136,3 +137,148 @@ def which_prefix(path): | |
# we cannot chop off any more directories, so we didn't find it | ||
return None | ||
prefix = dirname(prefix) | ||
|
||
if parse_version(conda.__version__) >= parse_version("4.3"): | ||
from conda.exports import FileMode, PathType | ||
FileMode, PathType = FileMode, PathType | ||
from conda.export import EntityEncoder | ||
EntityEncoder = EntityEncoder | ||
from conda.export import CrossPlatformStLink | ||
CrossPlatformStLink = CrossPlatformStLink | ||
else: | ||
from json import JSONEncoder | ||
from os import lstat | ||
import os | ||
|
||
class PathType(Enum): | ||
""" | ||
Refers to if the file in question is hard linked or soft linked. Originally designed to be used | ||
in paths.json | ||
""" | ||
hardlink = "hardlink" | ||
softlink = "softlink" | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
def __json__(self): | ||
return self.name | ||
|
||
|
||
class FileMode(Enum): | ||
""" | ||
Refers to the mode of the file. Originally referring to the has_prefix file, but adopted | ||
for paths.json | ||
""" | ||
text = 'text' | ||
binary = 'binary' | ||
|
||
def __str__(self): | ||
return "%s" % self.value | ||
|
||
|
||
class EntityEncoder(JSONEncoder): | ||
# json.dumps(obj, cls=SetEncoder) | ||
def default(self, obj): | ||
if hasattr(obj, 'dump'): | ||
return obj.dump() | ||
elif hasattr(obj, '__json__'): | ||
return obj.__json__() | ||
elif hasattr(obj, 'to_json'): | ||
return obj.to_json() | ||
elif hasattr(obj, 'as_json'): | ||
return obj.as_json() | ||
return JSONEncoder.default(self, obj) | ||
|
||
|
||
# work-around for python bug on Windows prior to python 3.2 | ||
# https://bugs.python.org/issue10027 | ||
# Adapted from the ntfsutils package, Copyright (c) 2012, the Mozilla Foundation | ||
class CrossPlatformStLink(object): | ||
_st_nlink = None | ||
|
||
def __call__(self, path): | ||
return self.st_nlink(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test or remove |
||
|
||
@classmethod | ||
def st_nlink(cls, path): | ||
if cls._st_nlink is None: | ||
cls._initialize() | ||
return cls._st_nlink(path) | ||
|
||
@classmethod | ||
def _standard_st_nlink(cls, path): | ||
return lstat(path).st_nlink | ||
|
||
@classmethod | ||
def _windows_st_nlink(cls, path): | ||
st_nlink = cls._standard_st_nlink(path) | ||
if st_nlink != 0: | ||
return st_nlink | ||
else: | ||
# cannot trust python on Windows when st_nlink == 0 | ||
# get value using windows libraries to be sure of its true value | ||
# Adapted from the ntfsutils package, Copyright (c) 2012, the Mozilla Foundation | ||
GENERIC_READ = 0x80000000 | ||
FILE_SHARE_READ = 0x00000001 | ||
OPEN_EXISTING = 3 | ||
hfile = cls.CreateFile(path, GENERIC_READ, FILE_SHARE_READ, None, | ||
OPEN_EXISTING, 0, None) | ||
if hfile is None: | ||
from ctypes import WinError | ||
raise WinError( | ||
"Could not determine determine number of hardlinks for %s" % path) | ||
info = cls.BY_HANDLE_FILE_INFORMATION() | ||
rv = cls.GetFileInformationByHandle(hfile, info) | ||
cls.CloseHandle(hfile) | ||
if rv == 0: | ||
from ctypes import WinError | ||
raise WinError("Could not determine file information for %s" % path) | ||
return info.nNumberOfLinks | ||
|
||
@classmethod | ||
def _initialize(cls): | ||
if os.name != 'nt': | ||
cls._st_nlink = cls._standard_st_nlink | ||
else: | ||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858 | ||
import ctypes | ||
from ctypes import POINTER | ||
from ctypes.wintypes import DWORD, HANDLE, BOOL | ||
|
||
cls.CreateFile = ctypes.windll.kernel32.CreateFileW | ||
cls.CreateFile.argtypes = [ctypes.c_wchar_p, DWORD, DWORD, ctypes.c_void_p, | ||
DWORD, DWORD, HANDLE] | ||
cls.CreateFile.restype = HANDLE | ||
|
||
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211 | ||
cls.CloseHandle = ctypes.windll.kernel32.CloseHandle | ||
cls.CloseHandle.argtypes = [HANDLE] | ||
cls.CloseHandle.restype = BOOL | ||
|
||
class FILETIME(ctypes.Structure): | ||
_fields_ = [("dwLowDateTime", DWORD), | ||
("dwHighDateTime", DWORD)] | ||
|
||
class BY_HANDLE_FILE_INFORMATION(ctypes.Structure): | ||
_fields_ = [("dwFileAttributes", DWORD), | ||
("ftCreationTime", FILETIME), | ||
("ftLastAccessTime", FILETIME), | ||
("ftLastWriteTime", FILETIME), | ||
("dwVolumeSerialNumber", DWORD), | ||
("nFileSizeHigh", DWORD), | ||
("nFileSizeLow", DWORD), | ||
("nNumberOfLinks", DWORD), | ||
("nFileIndexHigh", DWORD), | ||
("nFileIndexLow", DWORD)] | ||
|
||
cls.BY_HANDLE_FILE_INFORMATION = BY_HANDLE_FILE_INFORMATION | ||
|
||
|
||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa364952 | ||
cls.GetFileInformationByHandle = ctypes.windll.kernel32.GetFileInformationByHandle | ||
cls.GetFileInformationByHandle.argtypes = [HANDLE, | ||
POINTER(BY_HANDLE_FILE_INFORMATION)] | ||
cls.GetFileInformationByHandle.restype = BOOL | ||
|
||
cls._st_nlink = cls._windows_st_nlink |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test or remove functionality if not used in conda-build