Exemple #1
0
    def rsync_file(self, payload):
        if self.result_cmd == "C":
            try:
                unpatched = open(CONFIG_DATA["src_file"], "rb")
                hashes = rsync.blockchecksums(unpatched)

                new_file = CONFIG_DATA["src_file"] + ".new"
                swap_path = CONFIG_DATA["src_file"] + "~"

                crypto_object = self.getCryptoObject()
                text = payload[8:]
                with open(swap_path, "wb") as out_file:
                    for chunk in crypto_object.decrypt(text, str(CONFIG_PASSWORD), key_length=32):
                        out_file.write(chunk)

                patchedfile = open(swap_path, "rb")
                delta = rsync.rsyncdelta(patchedfile, hashes)

                unpatched.seek(0)
                save_to = open(new_file, "wb")
                rsync.patchstream(unpatched, save_to, delta)

                save_to.close()
                patchedfile.close()
                unpatched.close()

                if os.path.exists(CONFIG_DATA["src_file"]):
                    os.remove(CONFIG_DATA["src_file"])

                os.rename(new_file, CONFIG_DATA["src_file"])

                if os.path.exists(swap_path):
                    os.remove(swap_path)
            except IOError, e:
                print e
            except Exception, e:
                raise Exception(e)
Exemple #2
0
    def wsync_file(self, user_id, file_id, data):
        print "[USER] User with %s sync files..." % (self.transport.getPeer())
        status, commentary = self.__get_standart_states()
        self.__checkUserCatalog(user_id)
        self.status = 'BUSY'
        operation = "WRT"
        try:
            unpatched = open(file_id, "rb")
            hashes = rsync.blockchecksums(unpatched)

            new_file = file_id + '.new'
            swap_path = file_id + '~'
            with open(swap_path, "wb") as out_file:
                out_file.write(data)

            patchedfile = open(swap_path, "rb")
            delta = rsync.rsyncdelta(patchedfile, hashes)

            unpatched.seek(0)
            save_to = open(new_file, "wb")
            rsync.patchstream(unpatched, save_to, delta)

            save_to.close()
            patchedfile.close()
            unpatched.close()

            if os.path.exists(file_id):
                os.remove(file_id)

            os.rename(new_file, file_id)

            if os.path.exists(swap_path):
                os.remove(swap_path)
        except IOError, argument:
            status = "E"
            commentary = argument