mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 23:43:31 +01:00
First commit towards a linking move_file().
This commit is contained in:
parent
4b11eed79f
commit
36550a0f23
2 changed files with 21 additions and 1 deletions
|
|
@ -480,7 +480,7 @@ class Item(LibModel):
|
|||
|
||||
# Files themselves.
|
||||
|
||||
def move_file(self, dest, copy=False):
|
||||
def move_file(self, dest, copy=False, link=False):
|
||||
"""Moves or copies the item's file, updating the path value if
|
||||
the move succeeds. If a file exists at ``dest``, then it is
|
||||
slightly modified to be unique.
|
||||
|
|
@ -491,6 +491,10 @@ class Item(LibModel):
|
|||
util.copy(self.path, dest)
|
||||
plugins.send("item_copied", item=self, source=self.path,
|
||||
destination=dest)
|
||||
elif link:
|
||||
util.link(self.path, dest)
|
||||
plugins.send("item_linked", item=self, source=self.path,
|
||||
destination=dest)
|
||||
else:
|
||||
plugins.send("before_item_moved", item=self, source=self.path,
|
||||
destination=dest)
|
||||
|
|
|
|||
|
|
@ -448,6 +448,22 @@ def move(path, dest, replace=False):
|
|||
raise FilesystemError(exc, 'move', (path, dest),
|
||||
traceback.format_exc())
|
||||
|
||||
def link(path, dest, replace=False):
|
||||
"""Create a symbolic link from path to `dest`. Raises an OSError if `dest` already exists, unless `replace` is True. Does nothing if `path` == `dest`."""
|
||||
if (samefile(path, dest)):
|
||||
return
|
||||
|
||||
path = syspath(path)
|
||||
dest = syspath(dest)
|
||||
if os.path.exists(dest) and not replace:
|
||||
raise FilesystemError('file exists', 'rename', (path, dest),
|
||||
traceback.format_exc())
|
||||
|
||||
try:
|
||||
os.symlink(path, dest)
|
||||
except OSError:
|
||||
print "WAAT!"
|
||||
|
||||
|
||||
def unique_path(path):
|
||||
"""Returns a version of ``path`` that does not exist on the
|
||||
|
|
|
|||
Loading…
Reference in a new issue