diff options
author | Gary Oberbrunner <garyo@genarts.com> | 2012-12-19 22:12:03 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2013-01-04 12:27:39 -0500 |
commit | 9056cabc1aed8bc31194022f5848573273492399 (patch) | |
tree | 22e55823174206318772ea3cf1066f8500e4e66c | |
parent | 2076f14f7eacfe4f8bb26ba60a1a927b4a5388f5 (diff) | |
download | dotfiles-9056cabc1aed8bc31194022f5848573273492399.tar.gz dotfiles-9056cabc1aed8bc31194022f5848573273492399.tar.bz2 dotfiles-9056cabc1aed8bc31194022f5848573273492399.zip |
Improve error handling for Windows symlinks
-rw-r--r-- | dotfiles/core.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/dotfiles/core.py b/dotfiles/core.py index dfa2278..52c26cc 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -55,7 +55,9 @@ else: kdll = windll.LoadLibrary("kernel32.dll") CreateSymbolicLinkA = windll.kernel32.CreateSymbolicLinkA + CreateSymbolicLinkA.restype = wintypes.BOOLEAN CreateSymbolicLinkW = windll.kernel32.CreateSymbolicLinkW + CreateSymbolicLinkW.restype = wintypes.BOOLEAN GetFileAttributesA = windll.kernel32.GetFileAttributesA GetFileAttributesW = windll.kernel32.GetFileAttributesW CloseHandle = windll.kernel32.CloseHandle @@ -81,7 +83,10 @@ else: else: stat = CreateSymbolicLinkA(name, target, is_dir) if win32_verbose: - print "CreateSymbolicLink(name=%s, target=%s, is_dir=%d) = %s"%(name,target,is_dir, stat) + print "CreateSymbolicLink(name=%s, target=%s, is_dir=%d) = %#x"%(name,target,is_dir, stat) + if not stat: + print "Can't create symlink %s -> %s"%(name, target) + raise ctypes.WinError() def symlink(target, name): CreateSymbolicLink(name, target, 0) @@ -211,8 +216,10 @@ else: def is_link_to(path, target): + def normalize(path): + return os.path.normcase(os.path.normpath(path)) return islink(path) and \ - realpath(path) == os.path.normpath(target) + normalize(realpath(path)) == normalize(target) class Dotfile(object): |