From 54087ec1881da74574fa99aba2d678bae615c864 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 19 Mar 2021 02:36:25 -0500 Subject: mlib: pathnames may be blobs POSIX filesystems do not enforce encodings, so we'll convert non-UTF-8 filenames to blobs for SQLite instead of failing on encoding errors. This should allow us to work on collections which feature legacy encodings. --- lib/dtas/mlib.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb index 026e931..eb7554a 100644 --- a/lib/dtas/mlib.rb +++ b/lib/dtas/mlib.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -# Copyright (C) 2015-2020 all contributors +# Copyright (C) 2015-2021 all contributors # License: GPL-3.0+ # frozen_string_literal: true # @@ -129,9 +129,13 @@ class DTAS::Mlib # :nodoc: comments.where(q).delete tmp.each do |tid, val| v = vals[val: val] - q[:val_id] = v ? v[:id] : vals.insert(val: val) - q[:tag_id] = tid - comments.insert(q) + begin + q[:val_id] = v ? v[:id] : vals.insert(val: val) + q[:tag_id] = tid + comments.insert(q) + rescue => e + warn "E: #{e.message} (#{e.class}) q=#{q.inspect} val=#{val.inspect}" + end end end end @@ -214,12 +218,16 @@ class DTAS::Mlib # :nodoc: end end + def maybe_blob(path) + path.valid_encoding? ? path : Sequel.blob(path) + end + def scan_file(path, st, parent_id) return if @suffixes !~ path || st.size == 0 # no-op if no change unless @force - if node = @db[:nodes][name: path, parent_id: parent_id] + if node = @db[:nodes][name: maybe_blob(path), parent_id: parent_id] return if st.ctime.to_i == node[:ctime] || node[:tlen] == DM_IGN end end @@ -271,14 +279,16 @@ class DTAS::Mlib # :nodoc: node_id = node.delete(:id) @db[:nodes].where(id: node_id).update(node.merge(q)) node[:id] = node_id + rescue => e + warn "E: #{e.message} (#{e.class}) node=#{node.inspect}" end def node_lookup(parent_id, name) - @db[:nodes][name: name, parent_id: parent_id] + @db[:nodes][name: maybe_blob(name), parent_id: parent_id] end def node_ensure(parent_id, name, tlen, ctime = nil) - q = { name: name, parent_id: parent_id } + q = { name: maybe_blob(name), parent_id: parent_id } if node = @db[:nodes][q] node_update_maybe(node, tlen, ctime) else @@ -289,6 +299,8 @@ class DTAS::Mlib # :nodoc: node[:id] = @db[:nodes].insert(node) end node + rescue => e + warn "E: #{e.message} (#{e.class}) q=#{q.inspect}" end def cd(path) -- cgit v1.2.3-24-ge0c7