Ejemplo n.º 1
0
 def remove_chunks_higher_replication_degree(self):
     data = Data(self.db_path)
     chunks = data.get_ordered_chunks_difference_replication_degree()
     el = 0
     while (self.backup_size < self.check_directory_size(self.backup_dir)):
         modification_id = chunks[el][4]
         chunk_number = chunks[el][1]
         sha256 = data.get_chunk_sha256(modification_id)
         data.delete_chunk_removed(chunk_number, sha256)
         file_name = self.backup_dir+str(sha256)+"_"+str(chunk_number)+".chunk"
         os.remove(file_name)
         message = "REMOVED " + VERSION + " " + sha256 + " " + str(chunk_number)
         self.shell.sendto(message, ("127.0.0.1", self.shell_port))
         el +=1
Ejemplo n.º 2
0
 def handle_shell_request(self, message,addr):
     args=message.split(" ")
     operation=args[0]
     data = Data(self.db_path)
     if(operation=="backup"):
         file_path=args[1]
         replication_degree=args[2]
         if(self.send_chunks(file_path,int(replication_degree))):
             self.shell.sendto("ok\n", addr)
         else:
             self.shell.sendto("fail\n", addr)
     elif(operation=="restore"):
         file_path=args[1]
         modifications=data.get_file_modifications(file_path)
         message="found "+ str(len(modifications))
         for modification in modifications:
             modification_date=modification[2]
             modification_date=modification_date[:10]+"T"+modification_date[11:19]
             message+= " " + modification_date
         self.shell.sendto(message,addr)
     
     elif(operation=="restoremodification"):
         file_name = args[1]
         option = int(args[2])
         modification = data.get_file_modifications(file_name)[option-1]
         sha256 = modification[1]
         chunks = int(modification[3])
         self.restore_file_modification(sha256, chunks)
         self.get_file(sha256, file_name,chunks)
         
     elif(operation=="delete"):
         file_name=args[1]
         self.request_file_deletion(file_name)
         
     elif(operation=="delete2"):
         file_name=args[1]
         self.request_file_deletion2(file_name)
         
     elif(operation=="REMOVED"):
         if(self.can_send_removed):
             file_id=message.split(" ")[2]
             chunk_number=message.split(" ")[3]
             self.reject_putchunks[file_id+chunk_number]=datetime.now() + timedelta(0,60)
             message+=CRLF+CRLF
             self.mc.sendto(message,(self.mc_address,self.mc_port))
             
     elif(operation=="deletechunk"):
         data= Data(self.db_path)
         file_id=message.split(" ")[1]
         chunk_number=message.split(" ")[2]
         filepath=self.backup_dir+file_id+"_"+chunk_number+".chunk"
         if (os.path.exists(filepath)):
             os.remove(filepath)
             data.delete_chunk_removed(chunk_number, file_id)
             
     elif(operation=="deleted"):
         file_id=message.split(" ")[1]
         if (file_id in self.pending_deletes):
             host=addr[0]
             try:
                 self.pending_deletes[file_id][1].remove(host)
                 if(len(self.pending_deletes[file_id][1])==0):
                     del self.pending_deletes[file_id]
             except:
                 pass