core icon indicating copy to clipboard operation
core copied to clipboard

resmgr: properly implement --overwrite, fix #690

Open kba opened this issue 3 years ago • 2 comments
trafficstars

Until now, the ocrd resmgr download --overwrite flag only had an effect if it was not set: Download would abort because the file already exists.

This PR adds an overwrite kwarg to the different methods handling download/copying/extraction. When set, the target directory/file are removed if they exist before data is written.

kba avatar Feb 13 '22 14:02 kba

Wouldn't it be simpler to just rmtree(fpath) after resource_manager.download's L251 if fpath.exists() and not overwrite:?

Simpler, yes, but I thought it would be less surprising if the overwrite case is handled by the download/copy method backends, because we have that pattern in other places too. You're right though, that all overwrite=True does is basically rm -rf dst before cp/download src dst.

kba avatar Feb 14 '22 08:02 kba

but I thought it would be less surprising if the overwrite case is handled by the download/copy method backends, because we have that pattern in other places too

I can only see downloading via requests in Resolver.download_to_directory, and in Workspace.download_file / download_url, which delegates to the former.

But even if you are planning on streamlining this into OcrdResourceManager.download in the future, it would still have to pass the top-level fpath.exists() test.

bertsky avatar Feb 14 '22 11:02 bertsky

But even if you are planning on streamlining this into OcrdResourceManager.download in the future, it would still have to pass the top-level fpath.exists() test.

9bc3aed85 Now it is done at the first fpath.exists() check, overwrite kwarg is unnecessarily convoluted.

kba avatar Dec 12 '22 17:12 kba