Skip to content

Store pull files in temp directory #253

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

JanCaha
Copy link
Contributor

@JanCaha JanCaha commented Jul 23, 2025

Change pull process so that downloaded files and file parts are stored in temporary directory (based on system) and not in .mergin folder in project. This should solve issue with external sync tools (ie. Dropbox, OneDrive, GDrive and others) where those files might be selected for sync and thus cannot be remove once MM pull job ends.

Fixes MerginMaps/qgis-plugin#464

@JanCaha
Copy link
Contributor Author

JanCaha commented Jul 23, 2025

In theory this could be a new function in MerginProject, depends on how we want to handle it.

@JanCaha JanCaha requested a review from MarcelGeo July 23, 2025 07:34
Copy link
Contributor

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check also the initial download of projects - currently we download the temporary data to the project directory (!) - e.g. photo.jpg will be first downloaded as photo.jpg.0 to the project directory (possibly also photo.jpg.1, photo.jpg.2 ... if the file is large and gets downloaded in multiple chunks), then it gets renamed / merged from chunks to the final photo.jpg. I think those temporary files should also go to a temporary directory first. (See _download_items() and UpdateTask.apply())

@@ -413,7 +413,8 @@ def pull_project_async(mc, directory):
# then we just download the whole file
_pulling_file_with_diffs = lambda f: "diffs" in f and len(f["diffs"]) != 0

temp_dir = mp.fpath_meta(f"fetch_{local_version}-{server_version}")
temp_dir_mergin = os.path.join(tempfile.gettempdir(), f"mergin-{mp.project_id()}")
temp_dir = os.path.join(temp_dir_mergin, f"fetch_{local_version}-{server_version}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using e.g. tempfile.TemporaryDirectory(prefix="mm-pull-") here and keeping the tmp dir reference in the pull job? That should be safer and always unique. We could also use it with delete=True flag and even ignore_cleanup_errors=True - and we don't need to worry about its cleanup, even in case of exceptions etc.

Copy link
Contributor

@MarcelGeo MarcelGeo Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good alternative to mkdtemp. I think we can not use with context here.

I think we can manually cleanup temp dir on the finish of pull (rmtree(temp_dir, ignore_errors=True) string alternatively use cleanup() method of TemporaryDirectory). But sure, just 🍒

there is qustionable also "unfinish_pull_dir" (where also some pull related staff is stored) and ".cache" dir (which is ok I think).

Copy link
Contributor

@MarcelGeo MarcelGeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just question about using different function shortcut for creating temp dir somehwere :)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16467542402

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.005%) to 80.329%

Totals Coverage Status
Change from base Build 16346707165: -0.005%
Covered Lines: 3467
Relevant Lines: 4316

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store temporary sync files to system temp to avoid shared drive problems
4 participants