Skip to content

Commit

Permalink
linkfiles: only link if the link doesn't already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
asmeurer committed Apr 29, 2014
1 parent f28e5cd commit 98c1fd8
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions linkfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import errno

from os import walk, symlink, makedirs
from os.path import join, relpath, abspath, exists, expanduser, split
from os.path import join, relpath, abspath, exists, lexists, expanduser, split

def fullpath(path):
return abspath(expanduser(path))
Expand Down Expand Up @@ -80,23 +80,18 @@ def main():
else:
destination = join(dest_head, relpath(join(dirpath, file),
dirpath))
if args.dry_run:
print("Would link:", end=' ')
else:
print("Linking:", end=' ')
print(fullpath(source), "to", fullpath(destination))

if not args.dry_run:
dir = split(fullpath(destination))[0]
if not exists(dir):
makedirs(dir, exist_ok=True)
try:
if not lexists(fullpath(destination)):
if args.dry_run:
print("Would link:", end=' ')
else:
print("Linking:", end=' ')
print(fullpath(source), "to", fullpath(destination))

if not args.dry_run:
dir = split(fullpath(destination))[0]
if not exists(dir):
makedirs(dir, exist_ok=True)
symlink(fullpath(source), fullpath(destination))
except OSError as e:
if e.errno == errno.EEXIST:
print("Could not link: destination file already exists")
else:
raise

if __name__ == '__main__':
sys.exit(main())

0 comments on commit 98c1fd8

Please sign in to comment.