diff options
author | Eric Wong <e@80x24.org> | 2015-11-29 02:38:28 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-12-13 12:37:30 +0000 |
commit | 1a7ebe167dbb13e791b901a13c804e13c5e59365 (patch) | |
tree | ca785bc23ea5b93bec1f74e369b7c089d46d41df /lib/dtas/mlib.rb | |
parent | f9ac7481be209778c4558ac008bd2b58f836f6fd (diff) | |
download | dtas-1a7ebe167dbb13e791b901a13c804e13c5e59365.tar.gz |
Files in a music library may be deleted or renamed, so our library should not persist old data. Unfortunately this double-stats all files, but using a hash for temporary storage could also bloat memory/disk usage and probably isn't worth it at the moment.
Diffstat (limited to 'lib/dtas/mlib.rb')
-rw-r--r-- | lib/dtas/mlib.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb index 9a112c9..34c0c82 100644 --- a/lib/dtas/mlib.rb +++ b/lib/dtas/mlib.rb @@ -273,6 +273,12 @@ class DTAS::Mlib cd(path) do # TODO: use parent_id if given dir = dir_vivify(@pwd.split(%r{/+}n), st.ctime.to_i) + dir_id = dir[:id] + + @db[:nodes].where(parent_id: dir_id).each do |node| + File.exist?(node[:name]) or remove_entry(node) + end + Dir.foreach('.', encoding: Encoding::BINARY) do |x| case x when '.', '..', %r{\n}n @@ -280,7 +286,7 @@ class DTAS::Mlib # mpd could not support them, either. So lets not bother for now. next else - scan_any(x, dir[:id]) + scan_any(x, dir_id) end end end @@ -393,4 +399,21 @@ class DTAS::Mlib end puts end + + def remove_entry(node) + root_id = root_node[:id] + node_id = node[:id] + q = { parent_id: node_id } + nodes = @db[:nodes] + nodes.where(q).each do |nd| + next if nd[:id] == root_id + case nd[:tlen] + when DM_DIR, DM_IGN + remove_entry(nd) + end + end + nodes.where(q).delete + @db[:comments].where(node_id: node_id).delete + nodes.where(id: node_id).delete + end end |