From a56c5e625be7889d91e50a5ba8c6bfa2c307756b Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Wed, 24 May 2023 16:10:31 +0100 Subject: [PATCH] more win fixes. --- src/chevah_compat/posix_filesystem.py | 7 ++++++- .../tests/normal/test_filesystem.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/chevah_compat/posix_filesystem.py b/src/chevah_compat/posix_filesystem.py index 54a0d02..ffe8d24 100644 --- a/src/chevah_compat/posix_filesystem.py +++ b/src/chevah_compat/posix_filesystem.py @@ -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, @@ -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, diff --git a/src/chevah_compat/tests/normal/test_filesystem.py b/src/chevah_compat/tests/normal/test_filesystem.py index f50a1f4..a757550 100644 --- a/src/chevah_compat/tests/normal/test_filesystem.py +++ b/src/chevah_compat/tests/normal/test_filesystem.py @@ -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) @@ -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))