Skip to content

Commit

Permalink
more win fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed May 24, 2023
1 parent ddd6aa3 commit a56c5e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/chevah_compat/posix_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ def _dirEntryToFileAttributes(self, entry):
if path.startswith('\\\\?\\') and path[5] == ':':
path = path[4:]

hardlinks = stats.st_nlink
if not hardlinks and os.name == 'nt':
# I don't know why on Windows we doing scandir.
hardlinks = 1

return FileAttributes(
name=name,
path=path,
Expand All @@ -765,7 +770,7 @@ def _dirEntryToFileAttributes(self, entry):
is_link=is_link,
modified=modified,
mode=mode,
hardlinks=stats.st_nlink,
hardlinks=hardlinks,
uid=stats.st_uid,
gid=stats.st_gid,
node_id=inode,
Expand Down
19 changes: 11 additions & 8 deletions src/chevah_compat/tests/normal/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,13 @@ def test_makeLink_windows_share(self):
self.assertContains(filename, result)
self.assertTrue(self.filesystem.exists(segments))
self.assertTrue(self.filesystem.isFolder(segments))
result = self.filesystem.getFileSize(segments)
self.assertEqual(0, result)

if self.os_family != 'nt':
# On Windows the folder will have a size.
# So we skip this check on Windows.
result = self.filesystem.getFileSize(segments)
self.assertEqual(0, result)

result = self.filesystem.getFileSize(file_segments)
self.assertEqual(len(data.encode('utf-8')), result)
self.filesystem.deleteFile(file_segments)
Expand All @@ -611,19 +616,17 @@ def test_makeLink_windows_share_invalid(self):
"""
It can create links to a non-existent Windows share.
"""
path, segments = self.tempPath()
if self.os_family == 'nt':
path = mk.fs.getEncodedPath(path)

path, segments = self.tempPathCleanup(win_encoded=True)
# We assume all slaves have the c:\temp folder.
share_name = 'no such share name-' + mk.string()
self.filesystem.makeLink(
target_segments=['UNC', '127.0.0.1', share_name],
link_segments=segments,
)
self.addCleanup(self.filesystem.deleteFolder, segments)

self.assertTrue(os.path.exists(path))
# The link target doens't exist, but the link file is created.
# This is why we use `lexists` and not `exists`
self.assertTrue(os.path.lexists(path))
self.assertEqual(
['UNC', '127.0.0.1', share_name],
self.filesystem.readLink(segments))
Expand Down

0 comments on commit a56c5e6

Please sign in to comment.