36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/command/backup.rb', line 36
def create_backup(data)
zipfilename = create_backup_filename(data)
pwd = Dir.pwd
novel_dir = Downloader.get_novel_data_dir_by_target(data["id"])
Dir.chdir(novel_dir)
paths = Dir.glob("**/*").keep_if { |path|
File.file?(path) && path.split("/", 2)[0] != BACKUP_DIR_NAME
}
FileUtils.mkdir(BACKUP_DIR_NAME) unless File.exist?(BACKUP_DIR_NAME)
Zip.unicode_names = true unless Helper.os_windows?
Zip::File.open(File.join(BACKUP_DIR_NAME, zipfilename), Zip::File::CREATE) do |zip|
paths.each do |path|
if Helper.os_windows?
zipped_filename = path.encode(Encoding::Windows_31J,
invalid: :replace, undef: :replace, replace: "_")
else
zipped_filename = path
end
zip.add(zipped_filename, path)
end
end
Dir.chdir(pwd)
zipfilename
end
|