コード例 #1
0
ファイル: tests.py プロジェクト: Active8-BV/cryptobox_app
 def test_hash_rename(self):
     """
     test_hash_rename
     """
     self.unzip_testfiles_clean()
     fpath = "testdata/test/smalltest/test.cpp"
     file_dict = read_file_to_fdict(fpath)
     filehash = make_sha1_hash_file("blob " + str(file_dict["st_size"]) + "\0", fpath)
     os.system("mv testdata/test/smalltest/test.cpp testdata/test/smalltest/test2.cpp")
     fpath = "testdata/test/smalltest/test2.cpp"
     file_dict = read_file_to_fdict(fpath)
     filehash2 = make_sha1_hash_file("blob " + str(file_dict["st_size"]) + "\0", fpath)
     self.assertEqual(filehash, filehash2)
コード例 #2
0
ファイル: cba_sync.py プロジェクト: Active8-BV/cryptobox_app
def diff_files_locally(memory, options, localindex, serverindex):
    """
    diff_files_locally
    @type memory: Memory
    @type options: optparse.Values, instance
    @type localindex: dict
    @type serverindex: dict
    """
    local_pathnames = [(localindex["dirnames"][d]["dirname"], localindex["dirnames"][d]["filenames"]) for d in localindex["dirnames"] if len(localindex["dirnames"][d]["filenames"]) > 0]
    local_pathnames_set = set()
    file_uploads = []

    for ft in local_pathnames:
        for fname in ft[1]:
            if not str(fname["name"]).startswith("."):
                local_path = os.path.join(ft[0], fname["name"])
                local_pathnames_set.add(str(local_path))

    for local_path in local_pathnames_set:
        if os.path.exists(local_path):
            seen_local_path_before, memory = in_local_path_history(memory, local_path)
            rel_local_path = local_path.replace(options.dir, "")
            upload_file_object = {"local_path": local_path,
                                  "parent_short_id": None,
                                  "rel_path": rel_local_path }

            corresponding_server_nodes = [x for x in serverindex["doclist"] if x["doc"]["m_path_p64s"] == upload_file_object["rel_path"]]

            if not seen_local_path_before:
                if len(corresponding_server_nodes) == 0 or not corresponding_server_nodes:
                    file_uploads.append(upload_file_object)
                else:
                    filedata, localindex = make_cryptogit_hash(upload_file_object["local_path"], options.dir, localindex)

                    if not corresponding_server_nodes[0]:
                        file_uploads.append(upload_file_object)
                    else:
                        if not strcmp(corresponding_server_nodes[0]["content_hash_latest_timestamp"][0], filedata["filehash"]):
                            file_uploads.append(upload_file_object)
                        else:
                            memory = add_local_path_history(memory, upload_file_object["local_path"])

            else:
                # is it changed?
                if len(corresponding_server_nodes) != 0:
                    filestats = read_file_to_fdict(local_path)

                    if filestats and corresponding_server_nodes[0]:
                        try:
                            if filestats["st_ctime"] > corresponding_server_nodes[0]["content_hash_latest_timestamp"][1]:
                                filedata, localindex = make_cryptogit_hash(local_path, options.dir, localindex)
                                if filedata["filehash"] != corresponding_server_nodes[0]["content_hash_latest_timestamp"][0]:
                                    file_uploads.append(upload_file_object)

                        except:
                            raise

    file_del_local = []
    server_paths = [str(os.path.join(options.dir, x["doc"]["m_path_p64s"].lstrip(os.path.sep))) for x in serverindex["doclist"]]
    for local_path in local_pathnames_set:
        if os.path.exists(local_path):
            if local_path not in server_paths:
                seen_local_path_before, memory = in_local_path_history(memory, local_path)

                if seen_local_path_before:
                    file_del_local.append(local_path)

    return file_uploads, file_del_local, memory, localindex