From Adrien Destugues <pulkomandy@xxxxxxxxx>:
Adrien Destugues has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/3672 ;)
Change subject: Package Kit: smarter download resume
......................................................................
Package Kit: smarter download resume
Pick the most advanced partial download to resume from if there are
multiple ones.
Fixes the remaining part of #16744.
---
M src/kits/package/manager/PackageManager.cpp
1 file changed, 17 insertions(+), 4 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/72/3672/1
diff --git a/src/kits/package/manager/PackageManager.cpp
b/src/kits/package/manager/PackageManager.cpp
index 6b78ecc..444666a 100644
--- a/src/kits/package/manager/PackageManager.cpp
+++ b/src/kits/package/manager/PackageManager.cpp
@@ -573,16 +573,29 @@
BString globPath = parent.Path();
globPath << "/*/" << fileName;
glob_t globbuf;
- if (glob(globPath.String(), 0, NULL, &globbuf)
== 0) {
+ if (glob(globPath.String(), GLOB_NOSORT, NULL,
&globbuf) == 0) {
+ off_t size = 0;
+ off_t newSize = 0;
+ const char* bestFile = NULL;
+
+ for (size_t i = 0; i <
globbuf.gl_pathc; i++) {
+ BNode node(globbuf.gl_pathv[i]);
+ if (node.GetSize(&newSize) ==
B_OK && newSize > size) {
+ size = newSize;
+ bestFile =
globbuf.gl_pathv[i];
+ }
+ }
+
path.Append(fileName);
- if
(BCopyEngine().CopyEntry(globbuf.gl_pathv[0],
- path.Path()) == B_OK) {
+ if (bestFile != NULL &&
BCopyEngine().CopyEntry(bestFile,
+ path.Path()) == B_OK) {
alreadyDownloaded =
FetchUtils::IsDownloadCompleted(
path.Path());
printf("Re-using download '%s'
from previous "
- "transaction%s\n",
globbuf.gl_pathv[0],
+ "transaction%s\n",
bestFile,
alreadyDownloaded ? ""
: " (partial)");
}
+ globfree(&globbuf);
}
}
--
To view, visit https://review.haiku-os.org/c/haiku/+/3672
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I0ed7daf42e0346632918552e97d660b4946405cd
Gerrit-Change-Number: 3672
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange