-
Notifications
You must be signed in to change notification settings - Fork 68
For gpkg file restore always use diff checkpoints #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,16 +337,23 @@ def download_project_file( | |
| else: | ||
| file_path = fh.location | ||
|
|
||
| if version and not diff: | ||
| project.storage.restore_versioned_file( | ||
| file, ProjectVersion.from_v_name(version) | ||
| ) | ||
|
|
||
| abs_path = os.path.join(project.storage.project_dir, file_path) | ||
| # check file exists (e.g. there might have been issue with restore) | ||
|
|
||
| if not os.path.exists(abs_path): | ||
| logging.error(f"Missing file {namespace}/{project_name}/{file_path}") | ||
| abort(404) | ||
| if version and not diff: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably add some reolving map on the start of controller, where we can make actions based on this version and diff attributes. If not version and diff: abort Where is handled a non gpkg file? |
||
| project.storage.restore_versioned_file( | ||
| file, ProjectVersion.from_v_name(version) | ||
| ) | ||
|
|
||
| # check again after restore | ||
| if not os.path.exists(abs_path): | ||
| logging.error( | ||
| f"Failed to restore {namespace}/{project_name}/{file_path}" | ||
| ) | ||
| abort(404) | ||
| else: | ||
| logging.error(f"Missing file {namespace}/{project_name}/{file_path}") | ||
| abort(404) | ||
|
|
||
| response = prepare_download_response(project.storage.project_dir, file_path) | ||
| return response | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,45 +304,31 @@ def test_create_diff_checkpoint(diff_project): | |
|
|
||
| basefile, diffs = FileHistory.diffs_chain(file_path_id, 32) | ||
| assert basefile.project_version_name == 9 | ||
| # so far we only have individual diffs | ||
| assert len(diffs) == 22 | ||
| assert len(diffs) == 3 | ||
| # also a lower diff rank was created | ||
| lower_diff = FileDiff.query.filter_by(version=24, rank=1).first() | ||
| assert os.path.exists(lower_diff.abs_path) | ||
|
|
||
| # diff for v17-v20 from individual diffs | ||
| assert FileDiff.can_create_checkpoint(file_path_id, Checkpoint(1, 5)) is True | ||
| diff = FileDiff( | ||
| basefile=basefile, path=f"test.gpkg-diff-{uuid.uuid4()}", version=20, rank=1 | ||
| ) | ||
| db.session.add(diff) | ||
| db.session.commit() | ||
| assert not os.path.exists(diff.abs_path) | ||
| diff = FileDiff.query.filter_by( | ||
| file_path_id=file_path_id, version=20, rank=1 | ||
| ).first() | ||
| os.remove(diff.abs_path) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removed assert which was before here on this line? |
||
| diff.construct_checkpoint() | ||
| assert os.path.exists(diff.abs_path) | ||
|
|
||
| basefile, diffs = FileHistory.diffs_chain(file_path_id, 20) | ||
| assert basefile.project_version_name == 9 | ||
| # 6 individual diffs (v11-v16) + merged diff (v17-v20) as the last one | ||
| assert len(diffs) == 7 | ||
| # individual diff v12 + (v13-v16) + (v17-v20) as the last one | ||
| assert len(diffs) == 3 | ||
| assert diffs[-1] == diff | ||
|
|
||
| # repeat - nothing to do | ||
| mtime = os.path.getmtime(diff.abs_path) | ||
| diff.construct_checkpoint() | ||
| assert mtime == os.path.getmtime(diff.abs_path) | ||
|
|
||
| # some lower rank diffs still missing | ||
| assert not FileDiff.query.filter_by(version=24, rank=1).count() | ||
|
|
||
| # diff for v17-v32 with merged diffs, this will also create lower missing ranks | ||
| diff = FileDiff( | ||
| basefile=basefile, path=f"test.gpkg-diff-{uuid.uuid4()}", version=32, rank=2 | ||
| ) | ||
| db.session.add(diff) | ||
| db.session.commit() | ||
| diff.construct_checkpoint() | ||
| assert os.path.exists(diff.abs_path) | ||
| lower_diff = FileDiff.query.filter_by(version=24, rank=1).first() | ||
| assert os.path.exists(lower_diff.abs_path) | ||
|
|
||
| # assert gpkg diff is the same as it would be from merging all individual diffs | ||
| individual_diffs = ( | ||
| FileDiff.query.filter_by(file_path_id=file_path_id, rank=0) | ||
|
|
@@ -368,11 +354,12 @@ def test_create_diff_checkpoint(diff_project): | |
|
|
||
| # geodiff failure | ||
| mock.side_effect = GeoDiffLibError | ||
| diff = FileDiff( | ||
| basefile=basefile, path=f"test.gpkg-diff-{uuid.uuid4()}", version=16, rank=1 | ||
| ) | ||
| db.session.add(diff) | ||
| db.session.commit() | ||
| diff = FileDiff.query.filter_by( | ||
| file_path_id=file_path_id, version=16, rank=1 | ||
| ).first() | ||
| if os.path.exists(diff.abs_path): | ||
| os.remove(diff.abs_path) | ||
|
|
||
| diff.construct_checkpoint() | ||
| assert mock.called | ||
| assert not os.path.exists(diff.abs_path) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to follow commit in the end?