Sha256: dc64b5f460feee56d5af2fba9207821aacd0f64ff558453f157cddb00c361d66
Contents?: true
Size: 793 Bytes
Versions: 7
Compression:
Stored size: 793 Bytes
Contents
module Riserva::Commands class CreateArchive < ApplicationCommand def call(path) return broadcast(:invalid) unless super file = archive_name create_archive(file) ? broadcast(:ok, file) : broadcast(:failed) end private def valid? @path.directory? end def create_archive(file) system("tar cjf #{file} -C #{@path.parent} #{@path.basename}") end def archive_name time_prefix = Time.now.getlocal.strftime('%Y%m%d_%H%M') filename = @path.basename.to_s.downcase File.join(archive_location, "#{time_prefix}_#{filename}.tar.bz2") end def archive_location location = Pathname.new(Riserva::Config.read('storage_location')) location.mkpath unless location.exist? location end end end
Version data entries
7 entries across 7 versions & 1 rubygems