Skip to content

Commit

Permalink
fox SymlinkView, do not check mtimes, but verify the links' existence
Browse files Browse the repository at this point in the history
and targets

First, this also a file-system only operation, i.e. cheap, and secondly,
the mtime code follows symlinks, so it is not really quite obscure
whether and why it does the right thing for symlinks
  • Loading branch information
wisp3rwind committed May 6, 2020
1 parent 30a2175 commit ffa7af8
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions beetsplug/alternatives.py
Expand Up @@ -183,6 +183,29 @@ def parse_config(self, config):
dir = os.path.join(self.lib.directory, dir)
self.directory = dir

def item_change_actions(self, item, path, dest):
""" Returns the necessary actions for items that were previously in the
external collection, but might require metadata updates.
"""
actions = []

if not util.samefile(path, dest):
actions.append(self.MOVE)

item_mtime_alt = os.path.getmtime(syspath(path))
if (item_mtime_alt < os.path.getmtime(syspath(item.path))):
actions.append(self.WRITE)
album = item.get_album()

if album:
if (album.artpath and
os.path.isfile(syspath(album.artpath)) and
(item_mtime_alt
< os.path.getmtime(syspath(album.artpath)))):
actions.append(self.SYNC_ART)

return actions

def matched_item_action(self, item):
path = self.get_path(item)
if path and os.path.lexists(syspath(path)):
Expand All @@ -192,20 +215,8 @@ def matched_item_action(self, item):
if not path_ext == dest_ext:
# formats config option changed
return (item, [self.REMOVE, self.ADD])
actions = []
if not util.samefile(path, dest):
actions.append(self.MOVE)
item_mtime_alt = os.path.getmtime(syspath(path))
if (item_mtime_alt < os.path.getmtime(syspath(item.path))):
actions.append(self.WRITE)
album = item.get_album()
if album:
if (album.artpath and
os.path.isfile(syspath(album.artpath)) and
(item_mtime_alt
< os.path.getmtime(syspath(album.artpath)))):
actions.append(self.SYNC_ART)
return (item, actions)
else:
return (item, self.item_change_actions(item, path, dest))
else:
return (item, [self.ADD])

Expand Down Expand Up @@ -376,6 +387,21 @@ def parse_config(self, config):

super(SymlinkView, self).parse_config(config)

def item_change_actions(self, item, path, dest):
""" Returns the necessary actions for items that were previously in the
external collection, but might require metadata updates.
"""
actions = []

if not path == dest:
# The path of the link itself changed
actions.append(self.MOVE)
elif not util.samefile(path, item.path):
# link target changed
actions.append(self.MOVE)

return actions

def update(self, create=None):
for (item, actions) in self.items_actions():
dest = self.destination(item)
Expand Down

0 comments on commit ffa7af8

Please sign in to comment.