Skip to contentSkip to conversation

fetch2: Handle missing donestamp file when content is valid

PATCH Superseded Nathan Rossi 2 participants 2 messages Feb 2, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fetch2: Handle missing donestamp file when content is valid

In order to allow users to manually populate the download directory with valid content change the assumption that missing the donestamp file means unfetched content.

This allows users to populate the download dir without needing to create dummy .done files such that a user does not need a PREMIRROR when using BB_NO_NETWORK to provide valid content files in the download directory.

Also added test cases to cover this use case and additional use cases where for example the fetcher does not support checksums.

---
Changes in v2:
* Added test cases for the 4 common donestamp cases

---
 lib/bb/fetch2/__init__.py | 13 ++++-----
 lib/bb/tests/fetch.py     | 68 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 8 deletions(-)
lib/bb/fetch2/__init__.py +5 -8
index 6bd040493e..7f290bb930 100644
@@ -643,16 +643,13 @@ def verify_donestamp(ud, d, origud=None):
     if not ud.needdonestamp or (origud and not origud.needdonestamp):
         return True
 
-    if not os.path.exists(ud.donestamp):
-        return False
-
     if (not ud.method.supports_checksum(ud) or
         (origud and not origud.method.supports_checksum(origud))):
-        # done stamp exists, checksums not supported; assume the local file is
-        # current
-        return True
+        # if done stamp exists and checksums not supported; assume the local
+        # file is current
+        return os.path.exists(ud.donestamp)
 
-    if not os.path.exists(ud.localpath):
+    if not os.path.exists(ud.localpath) and os.path.exists(ud.donestamp):
         # done stamp exists, but the downloaded file does not; the done stamp
         # must be incorrect, re-trigger the download
         bb.utils.remove(ud.donestamp)
@@ -662,7 +659,7 @@ def verify_donestamp(ud, d, origud=None):
     # Only re-use the precomputed checksums if the donestamp is newer than the
     # file. Do not rely on the mtime of directories, though. If ud.localpath is
     # a directory, there will probably not be any checksums anyway.
-    if (os.path.isdir(ud.localpath) or
+    if os.path.exists(ud.donestamp) and (os.path.isdir(ud.localpath) or
             os.path.getmtime(ud.localpath) < os.path.getmtime(ud.donestamp)):
         try:
             with open(ud.donestamp, "rb") as cachefile:
lib/bb/tests/fetch.py +68 -0

80 lines not on this page · raw message

Signature · 1 line
2.15.1
#1 lore raw
Quoted 12 lines · Nathan Rossi

In order to allow users to manually populate the download directory with
valid content change the assumption that missing the donestamp file means unfetched content.

This allows users to populate the download dir without needing to create
dummy .done files such that a user does not need a PREMIRROR when using
BB_NO_NETWORK to provide valid content files in the download directory.

Quoted 7 lines

Also added test cases to cover this use case and additional use cases where for example the fetcher does not support checksums.

---
Changes in v2:
  * Added test cases for the 4 common donestamp cases

Looks good, thanks for the tests, over the longer term that are proving invaluable!

Cheers,

Richard