core
core copied to clipboard
resmgr: properly implement --overwrite, fix #690
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.
Wouldn't it be simpler to just
rmtree(fpath)afterresource_manager.download's L251if 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.
but I thought it would be less surprising if the
overwritecase 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.
But even if you are planning on streamlining this into
OcrdResourceManager.downloadin the future, it would still have to pass the top-levelfpath.exists()test.
9bc3aed85 Now it is done at the first fpath.exists() check, overwrite kwarg is unnecessarily convoluted.