diff --git a/mail-compress b/mail-compress index 5624bd1..29dc27f 100755 --- a/mail-compress +++ b/mail-compress @@ -34,7 +34,7 @@ require 'pathname' require 'set' def maildirlock path - return yield # currently deactivated, maildirlock does not work + return yield # currently deactivated io = IO.popen ['/usr/lib/dovecot/maildirlock', path.to_s, '10'], out: %i[child out] lockpidfile = Pathname.new io.read pid, pst = Process.wait2 @@ -99,7 +99,18 @@ def unxz mf, tf if 0 == pst.exitstatus true else - log " Compression failed for: #{mf}" + log " Decompression [xz] failed for: #{mf}" + false + end +end + +def unzstd mf, tf + pid = Process.spawn 'zstd', '-d', umask: 0177, in: mf.to_s, out: tf.to_s, close_others: true + _pid, pst = Process.waitpid2( pid) + if 0 == pst.exitstatus + true + else + log " Decompression [zstd] failed for: #{mf}" false end end @@ -230,6 +241,20 @@ def process xf end end + if false and :zst == fs + nf = mf.new compressed: false + tf = nf.new dir: :tmp + return log " Uncompressed mail already exist: #{nf}" if nf.exist? + return log " Temporary file already exist: #{tf}" if tf.exist? + STDERR.print "<\r" + return unless unzstd mf.to_s, tf.to_s + STDERR.print "<<\r" + restat tf, stat + place mf, nf, tf + STDERR.print "<<<\r" + return process(nf) + end + if :xz == fs nf = mf.new compressed: false tf = nf.new dir: :tmp