From a9aea04a27e0b35025a1e1204b382e148a8bb0df Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Thu, 30 Jan 2020 19:17:28 +0100 Subject: [PATCH] upload is ok --- src/server/handlers.cr | 2 +- src/tests/context-tests.cr | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/server/handlers.cr b/src/server/handlers.cr index 6fcc981..dcc6285 100644 --- a/src/server/handlers.cr +++ b/src/server/handlers.cr @@ -60,7 +60,7 @@ def hdl_upload(request : FileStorage::UploadRequest, user : User) : FileStorage: # TODO: verify the rights and quotas of the user # First: check if the file already exists - transfer_info = Context.db_by_filedigest.get request.file.digest + transfer_info = Context.db_by_filedigest.get? request.file.digest if transfer_info.nil? # In case file informations aren't already registered # which is normal at this point diff --git a/src/tests/context-tests.cr b/src/tests/context-tests.cr index 987d483..aa01070 100644 --- a/src/tests/context-tests.cr +++ b/src/tests/context-tests.cr @@ -2,12 +2,15 @@ require "../common/filestorage.cr" require "ipc" require "option_parser" +require "../common/utils.cr" require "../server/context.cr" filename = "./README.md" tags = "readme example" +chunk_number_to_remove = 1 + OptionParser.parse do |parser| parser.on "-f file-to-transfer", "--file to-transfer", @@ -15,6 +18,12 @@ OptionParser.parse do |parser| filename = opt end + 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 + parser.on "-d database-directory", "--db-dir directory", "DB directory" do |opt| @@ -29,24 +38,31 @@ OptionParser.parse do |parser| end parser.unknown_args do |args| - pp! args + pp! args if args.size > 0 end end -pp! Context - fileinfo : FileStorage::FileInfo? = nil File.open(filename) do |file| fileinfo = FileStorage::FileInfo.new file, tags.split(' ') end -pp! fileinfo - transfer_info = TransferInfo.new 1000, fileinfo.not_nil! +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 + Context.db << transfer_info +# remove the chunk once the information is recorded in the db +remove_chunk_from_db transfer_info, chunk_number_to_remove + Context.db.each do |ti| pp! ti end