From 152cd07e16cb695d23ae8727b6767b2237029ece Mon Sep 17 00:00:00 2001 From: Sergei Rybakov Date: Mon, 30 Dec 2024 12:30:57 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20double=20download=20of=20f?= =?UTF-8?q?iles=20in=20http=20(#919)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix double download * comment --- lamindb_setup/core/upath.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lamindb_setup/core/upath.py b/lamindb_setup/core/upath.py index 4f92ab29..58e0d072 100644 --- a/lamindb_setup/core/upath.py +++ b/lamindb_setup/core/upath.py @@ -264,7 +264,17 @@ def download_to(self, local_path: UPathStr, print_progress: bool = True, **kwarg ) kwargs["callback"] = callback - self.fs.download(str(self), str(local_path), **kwargs) + cloud_path_str = str(self) + local_path_str = str(local_path) + + # otherwise fsspec calls fs._ls_real where it reads the body and parses links + # so the file is downloaded 2 times + # upath doesn't call fs.ls to infer type + if self.protocol in {"http", "https"} and self.stat().as_info()["type"] == "file": + self.fs.use_listings_cache = True + self.fs.dircache[cloud_path_str] = [] + + self.fs.download(cloud_path_str, local_path_str, **kwargs) def upload_from(