From f9659df3b37b5a40dd56b5d689e4eef07b25720d Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 30 Aug 2022 15:45:41 -0700 Subject: [PATCH] make sure that importing only takes the latest FileObject... the modified is the correct, not mtime, as someone can put an "older" modified file, but at a later time, so it's assumed that the most recently modified fileobject has the most up to date data.. --- ui/fixtures/cmd.dupfile.json | 47 ++++++++++++++++++++++++++++++++++++ ui/medashare/cli.py | 11 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 ui/fixtures/cmd.dupfile.json diff --git a/ui/fixtures/cmd.dupfile.json b/ui/fixtures/cmd.dupfile.json new file mode 100644 index 0000000..8f073a8 --- /dev/null +++ b/ui/fixtures/cmd.dupfile.json @@ -0,0 +1,47 @@ +[ +{ + "title": "gen ident", + "cmd": [ "genident", "name=A Test User" ], + "exit": 0 +}, +{ + "title": "that import can be done", + "cmd": [ "import" ], + "stdin": "{\"created_by_ref\": \"e7ad5ea1-1203-4951-9dca-ec852a7b8166\", \"foo\": [\"bar=baz\"], \"hashes\": [\"sha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\"], \"modified\": \"2022-08-21T00:13:51.245871Z\", \"sig\": \"g7k4plXjzz9y8YwJM2ncCIxaqlBpdbITPvKlDtfO7LSFmbZ-qcj0M0lN9h8twNU-n163dNsDGmQA4_s8pJB0liBHDwkjpYQvxfeztQDWNaVN7Xnh2MOj-wBzUbLTVnsJULXwVQrUjngzWjjGQ3jy6gwA\", \"tag\": [\"\"], \"type\": \"metadata\", \"uuid\": \"25ec10e6-c3d0-4363-a762-899dade7f93c\"}\n{\"created_by_ref\": \"2de7a389-410c-4755-8c62-f3254c7e971e\", \"dir\": \"\", \"filename\": \"FreeBSD-14.0-CURRENT-arm64-aarch64-ROCK64-20220331-d53927b0bae-254105.img.xz\", \"hashes\": [\"sha512:3eba2aa09a79fd7adec32ace93c6725e75b91a55192b5bfa827b893fae1c2cdbc040e282138387797f245c1f27da5e8ff7a02f59ff75c73b3d999d1e0a8752ad\"], \"id\": \"d9e8fc1a-9794-5e70-b67b-11d708ec8947\", \"modified\": \"2022-08-02T07:52:50.216428Z\", \"mtime\": \"2022-03-31T10:15:14.000000Z\", \"sig\": \"F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA\", \"size\": 551750948, \"type\": \"file\", \"uuid\": \"89544934-6ed9-46ca-b8d0-77c5209f798d\"}\n" +}, +{ + "special": "verify store object cnt", + "comment": "and the objects were imported", + "count": 2 +}, +{ + "title": "that when a newer file object is imported", + "cmd": [ "import" ], + "stdin": "{\"created_by_ref\": \"2de7a389-410c-4755-8c62-f3254c7e971e\", \"dir\": \"\", \"filename\": \"FreeBSD-14.0-CURRENT-arm64-aarch64-ROCK64-20220331-d53927b0bae-254105.img.xz\", \"hashes\": [\"sha512:3eba2aa09a79fd7adec32ace93c6725e75b91a55192b5bfa827b893fae1c2cdbc040e282138387797f245c1f27da5e8ff7a02f59ff75c73b3d999d1e0a8752ad\"], \"id\": \"d9e8fc1a-9794-5e70-b67b-11d708ec8947\", \"modified\": \"2022-08-03T07:52:50.216428Z\", \"mtime\": \"2022-03-05T10:10:14.000000Z\", \"sig\": \"F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA\", \"size\": 551750948, \"type\": \"file\", \"uuid\": \"fc536b84-8e1e-468f-995d-d41a3919a018\"}\n" +}, +{ + "special": "verify store object cnt", + "comment": "that there still is only two", + "count": 2 +}, +{ + "title": "and that the newer one is the one that survied, despite older mtime", + "cmd": [ "dump" ], + "stdout_re": ".*metadata.*\n.*modified.*2022-08-03.*\n" +}, +{ + "title": "that when an older file object is imported", + "cmd": [ "import" ], + "stdin": "{\"created_by_ref\": \"2de7a389-410c-4755-8c62-f3254c7e971e\", \"dir\": \"\", \"filename\": \"FreeBSD-14.0-CURRENT-arm64-aarch64-ROCK64-20220331-d53927b0bae-254105.img.xz\", \"hashes\": [\"sha512:3eba2aa09a79fd7adec32ace93c6725e75b91a55192b5bfa827b893fae1c2cdbc040e282138387797f245c1f27da5e8ff7a02f59ff75c73b3d999d1e0a8752ad\"], \"id\": \"d9e8fc1a-9794-5e70-b67b-11d708ec8947\", \"modified\": \"2022-08-01T07:52:50.216428Z\", \"mtime\": \"2022-03-05T10:10:14.000000Z\", \"sig\": \"F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA\", \"size\": 551750948, \"type\": \"file\", \"uuid\": \"dafd6e02-b871-49de-a6b2-17b590258610\"}\n" +}, +{ + "special": "verify store object cnt", + "comment": "that there still is only two", + "count": 2 +}, +{ + "title": "and that the newer one is the one that survied, despite older mtime", + "cmd": [ "dump" ], + "stdout_re": ".*metadata.*\n.*modified.*2022-08-03.*\n" +} +] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 2c78dd0..d3d9d4a 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -526,6 +526,17 @@ class ObjectStore(object): self._uuids[obj.uuid] = obj if obj.type == 'file': + objid = _makeuuid(obj.id) + if objid in self._uuids: + # pick which obj + oldobj = self._uuids[objid] + if oldobj.modified > obj.modified: + del self._uuids[obj.uuid] + obj = oldobj + else: + # get ride of old obj + del self._uuids[oldobj.uuid] + self._uuids[_makeuuid(obj.id)] = obj for j in obj.hashes: