[issue8879] Implement os.link on Windows
Changes by Brian Curtin cur...@acm.org: -- stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Amaury -- how does issue8879_unicode.diff look? Made the suggested change and added a test. -- stage: committed/rejected - patch review Added file: http://bugs.python.org/file19862/issue8879_unicode.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: Looks good, except that win32_error(link, NULL) should be called instead of posix_error(). errno is not guaranteed to be correctly set by the win32 api, and GetLastError() ususally gives more accurate errors. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Committed in r86854 with your win32_error suggestion. Thanks for your help and input. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Jesús Cea Avión j...@jcea.es added the comment: This patch seems to break quite a few buildbots. for instance: http://www.python.org/dev/buildbot/all/builders/x86%20OpenIndiana%203.x/builds/81/steps/test/logs/stdio test_mbcs_name (test.test_os.LinkTests) ... test test_os failed -- Traceback (most recent call last): File /export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/test/test_os.py, line 893, in test_mbcs_name self._test_link(self.file1, self.file2) File /export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/test/test_os.py, line 876, in _test_link with open(file1, w) as f1: UnicodeEncodeError: 'ascii' codec can't encode characters in position 15-16: ordinal not in range(128) -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Maybe the test should be Windows-only? I don't really know the answer...things tend to fall apart when I get involved with Unicode, encoding, codecs, etc. :/ -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Jesús Cea Avión j...@jcea.es added the comment: I am not familiar with this either, but better to restrict the test to platforms with actual mbcs encoding. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: I'll come up with a patch for Amaury's message. Hirokazu - I didn't see that MSDN page, thanks. Without st_ino, I'll need to find a way around the block of lines 1941-1954 in Lib/tarfile.py. That's what was causing a test failure in the first place because it ends up assuming Windows files are always REGTYPE, which sets some things later on in that function differently than they should be for links, namely tarinfo.size. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment: Umm, I'm not sure how to fix this yet, but if we create the function like os._stat_with_open_handle() which returns stat struct and open handle on windows, I think we can set/use st_ino. (Because FileID won't change while file is opened) I'm not sure if it is appropriate API change or not, though. :-( -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment: Or, use GetFileInformationByHandleEx on Vista or above, and NtQueryInformationFile under Vista. NtQueryInformationFile is windows internal function and MS may change its behavior, but probably we can think it won't happen on WinXP. # These functions are needed to get real filename from # open handle to set S_IEXEC. And provide windows specific functions os._open/os._lopen: open windows handle same as CreateFile in os.stat/os.lstat os._osfstat: stat for windows handle os._close: close windows handle and if the file is hard link, store windows handle anywhere in TarFile object. (I created branch for it, but I'm not sure I can do it) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Changes by Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp: -- Removed message: http://bugs.python.org/msg122421 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Removing link to #10027. It's fixed for py3k but the issue should stay open for backport to other branches. -- dependencies: -os.lstat/os.stat don't set st_nlink on Windows resolution: - fixed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Fixed in r86733. -- stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: The patch uses the ANSI version, and converts the filename from unicode to bytes; this will fail for names that cannot be encoded with the mbcs codec. All other functions in the posix module first try the Wide version of the win32 API, and use the ANSI version as a fallback, when the argument is a bytes string. PyUnicode_FSConverter should be avoided on Windows. See posix_mkdir() for a good example. Here is an example that fails on a Western Windows (where ANSI=cp1252). Note that even the file name is not encodable in mbcs, it is correctly displayed in the Explorer for example. name = \u65e5\u672c # Japan open(name, w).close() # Appears correctly in the explorer import os os.link(name, name + _1) Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character -- nosy: +amaury.forgeotdarc status: closed - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment: r86733 introduces st_ino setup in attribute_data_to_stat(), but Fild ID is not guaranteed to be same when file is not opened. So I think it's meaningful only for os.fstat(). Please see http://msdn.microsoft.com/en-us/library/aa363788%28v=VS.85%29.aspx -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: I created #10027 for the st_nlink issue to handle it separately. -- dependencies: +os.lstat/os.stat don't set st_nlink on Windows ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: test_tarfile fails with this patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment: I think this is because os.stat and os.lstat doesn't set st_nlink. It is only set via os.fstat. I'll attach quick hack patch. (Again, this is just quick hack patch) I confirmed this passes test_os and test_tarfile. -- Added file: http://bugs.python.org/file19091/py3k_quick_hack_for_issue8879.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Now that I think of it, that behavior is expected. Hard links are *supposed* to be different directory entries, so they would come out of that function as-is, and the current tests are correctly implemented. Uploaded to http://codereview.appspot.com/2290042 -- Added file: http://bugs.python.org/file19059/issue8879_v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: In a round-about way, that's what the tests do via sameopenfile. Maybe the behavior of os.path.samefile for Windows hard links should be documented? Possibly just a small note explaining that os.path.sameopenfile is an alternate solution due to how GetFinalPathNameByHandle works. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Brian Curtin cur...@acm.org added the comment: Here's a patch of the functionality. The doc change is small and easy, I'll add it shortly. One oddity is that os.path.samefile is False for a link and its source, but True for a symlink and its source. I find that to be quite odd, but stepping through the code I don't see where this is anything we are doing. I haven't been able to figure out if this is really expected behavior from Windows. When the files are open, os.path.sameopenfile shows that the link and its source are the same, which is expected. -- keywords: +needs review, patch stage: needs patch - patch review Added file: http://bugs.python.org/file18982/issue8879.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment: With following implementation, issamefile return True for hard link. I heard GetFinalPathNameByHandle returns different paths for hard links. import nt, os def issamefile(path1, path2): ... fd1 = os.open(path1, os.O_RDONLY) ... fd2 = os.open(path2, os.O_RDONLY) ... fi1 = nt._getfileinformation(fd1) ... fi2 = nt._getfileinformation(fd2) ... os.close(fd1) ... os.close(fd2) ... return fi1 == fi2 ... issamefile(src.txt, lnk.txt) True -- nosy: +ocean-city ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Changes by Brian Curtin cur...@acm.org: -- dependencies: +Add ntpath.sameopenfile support for Windows ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
New submission from Brian Curtin cur...@acm.org: Add os.link support for Windows (mostly a reminder to myself to finish the patch I have) -- assignee: brian.curtin components: Extension Modules, Windows messages: 106908 nosy: brian.curtin priority: normal severity: normal stage: needs patch status: open title: Implement os.link on Windows type: feature request versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8879] Implement os.link on Windows
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8879 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com