Ejemplo n.º 1
0
    def move(self, is_copy):
        did, app_id, content, response = post_json_param_pre_proc(
            self.response,
            "src_path",
            "dst_path",
            access_vault=VAULT_ACCESS_WR)
        if response is not None:
            return response

        src_name = content.get('src_path')
        src_name = filter_path_root(src_name)

        dst_name = content.get('dst_path')
        dst_name = filter_path_root(dst_name)

        path = get_save_files_path(did, app_id)
        src_full_path_name = (path / src_name).resolve()
        dst_full_path_name = (path / dst_name).resolve()

        if not src_full_path_name.exists():
            return self.response.response_err(NOT_FOUND, "src_name not exists")

        if dst_full_path_name.exists() and dst_full_path_name.is_file():
            return self.response.response_err(METHOD_NOT_ALLOWED,
                                              "dst_name file exists")

        dst_parent_folder = dst_full_path_name.parent
        if not dst_parent_folder.exists():
            if not create_full_path_dir(dst_parent_folder):
                return self.response.response_err(
                    INTERNAL_SERVER_ERROR, "make dst parent path dir error")
        try:
            if is_copy:
                if src_full_path_name.is_file():
                    shutil.copy2(src_full_path_name.as_posix(),
                                 dst_full_path_name.as_posix())
                    file_size = os.path.getsize(dst_full_path_name.as_posix())
                    inc_vault_file_use_storage_byte(did, file_size)
                else:
                    shutil.copytree(src_full_path_name.as_posix(),
                                    dst_full_path_name.as_posix())
                    dir_size = 0.0
                    get_dir_size(dst_full_path_name.as_posix(), dir_size)
                    inc_vault_file_use_storage_byte(did, dir_size)
            else:
                shutil.move(src_full_path_name.as_posix(),
                            dst_full_path_name.as_posix())
        except Exception as e:
            return self.response.response_err(INTERNAL_SERVER_ERROR,
                                              "Exception:" + str(e))

        return self.response.response_ok()
Ejemplo n.º 2
0
    def delete(self):
        did, app_id, content, response = post_json_param_pre_proc(
            self.response, "path", access_vault=VAULT_ACCESS_DEL)
        if response is not None:
            return response

        filename = content.get('path')
        filename = filter_path_root(filename)

        path = get_save_files_path(did, app_id)
        file_full_name = (path / filename).resolve()
        if file_full_name.exists():
            if file_full_name.is_dir():
                dir_size = 0.0
                get_dir_size(file_full_name.as_posix(), dir_size)
                shutil.rmtree(file_full_name)
                inc_vault_file_use_storage_byte(did, -dir_size)
            else:
                file_size = os.path.getsize(file_full_name.as_posix())
                file_full_name.unlink()
                inc_vault_file_use_storage_byte(did, -file_size)

        return self.response.response_ok()
Ejemplo n.º 3
0
    def backup_save_finish(self):
        did, content, err = did_post_json_param_pre_proc(self.response, "checksum_list")
        if err:
            return err

        checksum_list = content["checksum_list"]
        backup_path = get_vault_backup_path(did)
        if not backup_path.exists():
            return self.response.response_err(NOT_FOUND, f"{did} backup vault not found")

        backup_checksum_list = get_file_checksum_list(backup_path)
        for checksum in checksum_list:
            if checksum not in backup_checksum_list:
                return self.response.response_err(CHECKSUM_FAILED, f"{did} backup file checksum failed")

        total_size = 0.0
        total_size = get_dir_size(backup_path.as_posix(), total_size)
        update_vault_backup_service_item(did, VAULT_BACKUP_SERVICE_USE_STORAGE, total_size)
        return self.response.response_ok()
Ejemplo n.º 4
0
def count_file_system_storage_size(did):
    vault_path = get_vault_path(did)
    if not vault_path.exists() or vault_path.is_file():
        return 0.0
    return get_dir_size(vault_path.as_posix(), 0.0)
def count_vault_backup_storage_size(did):
    vault_path = get_vault_backup_path(did)
    storage_size = 0.0
    storage_size = get_dir_size(vault_path.as_posix(), storage_size)
    return storage_size
def count_file_system_storage_size(did):
    vault_path = get_vault_path(did)
    storage_size = 0.0
    storage_size = get_dir_size(vault_path.as_posix(), storage_size)
    return storage_size