lib/s3backup/manager.rb in s3backup-0.6.3 vs lib/s3backup/manager.rb in s3backup-0.6.4
- old
+ new
@@ -4,11 +4,23 @@
require 's3backup/s3log'
require 's3backup/tree_info'
require 's3backup/crypt'
module S3backup
class Manager
- DEFAULT_BUF_READ_SIZE=1024*1024*128
+ DEFAULT_BUF_READ_SIZE=1024*1024*64
+ def shell_name(str)
+ str.gsub!(/[!"$&'()*,:;<=>?\[\]^`{|}\s]/, '\\\\\&')
+ a=[]
+ str.each_byte{|i|
+ if i < 0x80
+ a.push(sprintf("%c",i))
+ else
+ a.push("'"+sprintf("%c",i) + "'")
+ end
+ }
+ return a.join;
+ end
def initialize(target,config)
@target = target
set_config(config)
end
def set_config(config)
@@ -37,19 +49,20 @@
Dir.foreach(dir) do |file|
next if /^\.+$/ =~ file
sub_dir.push(file) if File.directory?(dir+"/"+file)
end
exclude = ""
- exclude = exclude + " --exclude=" + sub_dir.map{|d| d.gsub(' ','\ ')}.join(" --exclude=") if sub_dir.length != 0
- cmd = "(cd #{File.dirname(dir).gsub(' ','\ ')};tar -czvf #{path.gsub(' ','\ ')} #{exclude} #{File.basename(dir).gsub(' ','\ ')} > /dev/null 2>&1)"
+ exclude = exclude + " --exclude=" + sub_dir.map{|d| shell_name(d)}.join(" --exclude=") if sub_dir.length != 0
+ cmd = "(cd #{shell_name(File.dirname(dir))};tar -czvf #{shell_name(path)} #{exclude} #{shell_name(File.basename(dir))}" +
+ " > /dev/null 2>&1)"
S3log.debug(cmd)
system(cmd)
unless $?.success?
raise "feiled #{cmd} execute. #{$?.inspect}"
end
end
def from_tgz(path,dir)
- cmd = "tar -xzvf #{path.gsub(' ','\ ')} -C #{dir.gsub(' ','\ ')} > /dev/null 2>&1"
+ cmd = "tar -xzvf #{shell_name(path)} -C #{shell_name(dir)} > /dev/null 2>&1"
S3log.debug(cmd)
system(cmd)
unless $?.success?
raise "feiled #{cmd} execute. #{$?.inspect}"
end