about summary refs log tree commit homepage
path: root/bin/dtas-tl
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dtas-tl')
-rwxr-xr-xbin/dtas-tl38
1 files changed, 24 insertions, 14 deletions
diff --git a/bin/dtas-tl b/bin/dtas-tl
index e58ee31..c7f4c83 100755
--- a/bin/dtas-tl
+++ b/bin/dtas-tl
@@ -43,7 +43,8 @@ def do_edit(c)
     track_id = $1.to_i
     orig_idx[track_id] = orig.size
     orig << track_id
-    tmp.write("#{Shellwords.escape(line)} =#{track_id}\n")
+    line = Shellwords.escape(line) if line.include?("\n")
+    tmp.write("#{line} =#{track_id}\n")
   end
   tmp.flush
 
@@ -100,13 +101,8 @@ def do_edit(c)
   non_existent = []
   add.each do |path, after_id|
     orig = path
-    path = Shellwords.split(path)[0]
-    path = File.expand_path(path)
-    unless File.exist?(path)
-      path = orig.dup
-      path = Shellwords.split(path)[0]
-      path = File.expand_path(path)
-    end
+    path = File.expand_path(orig)
+    path = File.expand_path(Shellwords.split(path)[0]) unless File.exist?(path)
 
     if File.exist?(path)
       cmd = %W(tl add #{path})
@@ -142,6 +138,8 @@ case cmd = ARGV[0]
 when 'cat'
   each_track(c) { |line| print "#{line}\n" }
 when 'prune'
+  c2 = nil
+  pending = 0
   each_track(c) do |line|
     line.sub!(/\A(\d+)=/n, '') or abort "unexpected line=#{line.inspect}\n"
     track_id = $1.to_i
@@ -153,7 +151,19 @@ when 'prune'
       warn "# #{line}: #{e.class}"
       # raise other exceptions
     end
-    c.req("tl remove #{track_id}") unless ok
+    unless ok
+      c2 ||= DTAS::UNIXClient.new
+      if pending > 5
+        c2.res_wait
+        pending -= 1
+      end
+      pending += 1
+      c2.req_start("tl remove #{track_id}")
+    end
+  end
+  while pending > 0
+    c2.res_wait
+    pending -= 1
   end
 when 'aac' # add-after-current
   ARGV.shift
@@ -178,11 +188,11 @@ when "reto"
   re = ARGV[1]
   time = ARGV[2]
   re = Regexp.quote(re) if fixed
-  re = ignorecase ? %r{#{re}}i : %r{#{re}}
-  get_track_ids(c).each do |track_id|
-    res = c.req("tl get #{track_id}")
-    res.sub!(/\A1 \d+=/, '')
-    if re =~ res
+  re = ignorecase ? %r{#{re}}in : %r{#{re}}n
+  each_track(c) do |line|
+    line.sub!(/\A(\d+)=/n, '') or abort "unexpected line=#{line.inspect}\n"
+    track_id = $1
+    if re =~ line
       req = %W(tl goto #{track_id})
       req << time if time
       res = c.req(req)