2020-01-29 15:56:49 +01:00
|
|
|
require "../common/filestorage.cr"
|
|
|
|
require "ipc"
|
|
|
|
require "option_parser"
|
|
|
|
|
2020-01-30 19:17:28 +01:00
|
|
|
require "../common/utils.cr"
|
2020-01-30 01:27:06 +01:00
|
|
|
require "../server/context.cr"
|
|
|
|
|
2020-01-29 15:56:49 +01:00
|
|
|
filename = "./README.md"
|
|
|
|
|
2020-01-30 01:27:06 +01:00
|
|
|
tags = "readme example"
|
|
|
|
|
2020-01-30 19:17:28 +01:00
|
|
|
chunk_number_to_remove = 1
|
|
|
|
|
2020-01-29 15:56:49 +01:00
|
|
|
OptionParser.parse do |parser|
|
|
|
|
parser.on "-f file-to-transfer",
|
|
|
|
"--file to-transfer",
|
|
|
|
"File to transfer (simulation)." do |opt|
|
|
|
|
filename = opt
|
|
|
|
end
|
|
|
|
|
2020-01-30 19:17:28 +01:00
|
|
|
parser.on "-c chunk_number_to_remove",
|
|
|
|
"--chunk-number chunk_number_to_remove",
|
|
|
|
"Once the upload stard, we remove chunks. This test the removal of one of them in the DB." do |opt|
|
|
|
|
chunk_number_to_remove = opt.to_i
|
|
|
|
end
|
|
|
|
|
2020-01-30 01:27:06 +01:00
|
|
|
parser.on "-d database-directory",
|
|
|
|
"--db-dir directory",
|
|
|
|
"DB directory" do |opt|
|
|
|
|
Context.file_info_directory = opt
|
|
|
|
Context.db_reconnect
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on "-t tags",
|
|
|
|
"--tags tags",
|
|
|
|
"Tags, example: 'fruit bio comestible'" do |opt|
|
|
|
|
tags = opt
|
|
|
|
end
|
|
|
|
|
2020-01-29 15:56:49 +01:00
|
|
|
parser.unknown_args do |args|
|
2020-01-30 19:17:28 +01:00
|
|
|
pp! args if args.size > 0
|
2020-01-29 15:56:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-30 01:27:06 +01:00
|
|
|
fileinfo : FileStorage::FileInfo? = nil
|
|
|
|
|
|
|
|
File.open(filename) do |file|
|
|
|
|
fileinfo = FileStorage::FileInfo.new file, tags.split(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
transfer_info = TransferInfo.new 1000, fileinfo.not_nil!
|
|
|
|
|
2020-01-30 19:17:28 +01:00
|
|
|
puts "transfer info of the file #{filename}"
|
|
|
|
puts
|
|
|
|
pp! transfer_info
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts "store file info then remove a chunk (number #{chunk_number_to_remove})"
|
|
|
|
puts
|
|
|
|
|
2020-01-30 01:27:06 +01:00
|
|
|
Context.db << transfer_info
|
|
|
|
|
2020-01-30 19:17:28 +01:00
|
|
|
# remove the chunk once the information is recorded in the db
|
|
|
|
remove_chunk_from_db transfer_info, chunk_number_to_remove
|
|
|
|
|
2020-01-30 01:27:06 +01:00
|
|
|
Context.db.each do |ti|
|
|
|
|
pp! ti
|
|
|
|
end
|
|
|
|
|