Bug 2558

Summary: Fetcher code incorrectly forces fetch of files which are in the download directory or mirror
Product: [Build System, Metadata & Runtime] Meta-yocto Reporter: Gary Thomas <gary>
Component: meta-yoctoAssignee: Richard Purdie <richard.purdie>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: High CC: laurentiu.serban, poky.bs.watcher, poky.watcher, sgw, shane.wang
Version: 1.2   
Target Milestone: 1.3 M1   
Hardware: x86   
OS: Multiple   
Whiteboard: Issue debugged and patch under discussion/testing
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: ---
Attachments:
Description Flags
Log showing fetch behaviour none

Description Gary Thomas 2012-06-07 22:10:35 UTC
Something in the fetcher code has changed such that the file
  gtk+-2.24.8.tar.bz2
is _always_ fetched from the network, even if it is already in a local mirror or download directory.

Tested with poky master de4cdfd6bc1280ac7ac0559b87734d26294ef773

Note: this is easy to test, just set BB_NO_NETWORK="1" in local.conf and try
to run 'bitbake gtk+ -c fetch'

Since my customers insist on zero network use during builds, this is a critical bug/regression.
Comment 1 Richard Purdie 2012-06-12 14:00:35 UTC
This isn't as simple as you're describing it since I tried setting BB_NO_NETWORK = "1" in my local.conf (confirmed set with -e) and my fetch for gtk+ suceeded. I then ran a -c cleanall, and the fetch then failed afterwards.

So is there something more specific about your environment needed to reproduce this?
Comment 2 Richard Purdie 2012-06-12 14:01:19 UTC
I'm wondering what values of PREMIRRORS and MIRRORS you're using?
Comment 3 Gary Thomas 2012-06-12 14:10:25 UTC
(In reply to comment #2)
> I'm wondering what values of PREMIRRORS and MIRRORS you're using?

I use "own-mirrors" set to a local directory, e.g.
  SOURCE_MIRROR_URL ?= "file:///work/misc/Poky/sources/"
  INHERIT += "own-mirrors"

My comment about BB_NO_NETWORK was just to show when the file is being downloaded, not that setting it causes the problem.  Sorry for any confusion.

The real issue is that the source tarball is being fetched from the network even if it exists in the mirror.
Comment 4 Gary Thomas 2012-06-12 14:25:20 UTC
Created attachment 572 [details]
Log showing fetch behaviour
Comment 5 Richard Purdie 2012-06-13 15:27:45 UTC
A quick question: Are you only seeing this for gtk+ ?

I think this patch might fix things:

--- a/bitbake/lib/bb/fetch2/local.py
+++ b/bitbake/lib/bb/fetch2/local.py
@@ -26,6 +26,7 @@ BitBake build tools.
 # Based on functions from the base bb module, Copyright 2003 Holger Schurig
 
 import os
+import urllib
 import bb
 import bb.utils
 from   bb import data
@@ -40,7 +41,7 @@ class Local(FetchMethod):
 
     def urldata_init(self, ud, d):
         # We don't set localfile as for this fetcher the file is already local!
-        ud.basename = os.path.basename(ud.url.split("://")[1].split(";")[0])
+        ud.basename = os.path.basename(urllib.unquote(ud.url.split("://")[1].split(";")[0]))
         return
 
     def localpath(self, url, urldata, d):
@@ -49,6 +50,7 @@ class Local(FetchMethod):
         """
         path = url.split("://")[1]
         path = path.split(";")[0]
+        path = urllib.unquote(path)
         newpath = path
         if path[0] != "/":
             filespath = data.getVar('FILESPATH', d, True)
Comment 6 Richard Purdie 2012-06-13 15:44:33 UTC
*** Bug 2546 has been marked as a duplicate of this bug. ***
Comment 7 Gary Thomas 2012-06-13 15:53:14 UTC
(In reply to comment #5)
> A quick question: Are you only seeing this for gtk+ ?

Correct.  It appears to be related to the '+' in the URL

> 
> I think this patch might fix things:

Tested this patch and it does work - the gtk+ tarball is no longer fetched from the network.

> 
> --- a/bitbake/lib/bb/fetch2/local.py
> +++ b/bitbake/lib/bb/fetch2/local.py
> @@ -26,6 +26,7 @@ BitBake build tools.
>  # Based on functions from the base bb module, Copyright 2003 Holger Schurig
>  
>  import os
> +import urllib
>  import bb
>  import bb.utils
>  from   bb import data
> @@ -40,7 +41,7 @@ class Local(FetchMethod):
>  
>      def urldata_init(self, ud, d):
>          # We don't set localfile as for this fetcher the file is already
> local!
> -        ud.basename = os.path.basename(ud.url.split("://")[1].split(";")[0])
> +        ud.basename =
> os.path.basename(urllib.unquote(ud.url.split("://")[1].split(";")[0]))
>          return
>  
>      def localpath(self, url, urldata, d):
> @@ -49,6 +50,7 @@ class Local(FetchMethod):
>          """
>          path = url.split("://")[1]
>          path = path.split(";")[0]
> +        path = urllib.unquote(path)
>          newpath = path
>          if path[0] != "/":
>              filespath = data.getVar('FILESPATH', d, True)
Comment 8 Gary Thomas 2012-06-13 15:58:48 UTC
With the patch above, there is now a slight change in behaviour.  As mentioned,
I use "own-mirrors" set up like this:
  BB_GENERATE_MIRROR_TARBALLS ?= "1"
  SOURCE_MIRROR_URL ?= "file:///work/misc/Poky/sources/"
  INHERIT += "own-mirrors"

Before, all files which exist on the mirror create a soft link in the local "downloads" directory, e.g.
  $ ls -l downloads/*v4l*
  lrwxrwxrwx 1 gthomas gthomas 63 Mar 27 10:57 downloads/git2_linuxtv.org.v4l-utils.git.tar.gz -> /local/poky-multi/sources/git2_linuxtv.org.v4l-utils.git.tar.gz

After this change, they are not fetched from the network but seem to be copied from the mirror.  I just ran this sequence:
  $ bitbake v4l-utils -c cleansstate
  $ rm downloads/*v4l*
  $ bitbake v4l-utils -c fetch
which now shows
  $ ls -l downloads/*v4l*
  -rw-rw-r-- 1 gthomas gthomas 1439674 Jun 13 09:53 downloads/git2_linuxtv.org.v4l-utils.git.tar.gz

I'll try to verify that the patch caused this change.
Comment 9 Gary Thomas 2012-06-13 16:01:28 UTC
(In reply to comment #8)
> With the patch above, there is now a slight change in behaviour.  As
> mentioned,
> I use "own-mirrors" set up like this:
>   BB_GENERATE_MIRROR_TARBALLS ?= "1"
>   SOURCE_MIRROR_URL ?= "file:///work/misc/Poky/sources/"
>   INHERIT += "own-mirrors"
> 
> Before, all files which exist on the mirror create a soft link in the local
> "downloads" directory, e.g.
>   $ ls -l downloads/*v4l*
>   lrwxrwxrwx 1 gthomas gthomas 63 Mar 27 10:57
> downloads/git2_linuxtv.org.v4l-utils.git.tar.gz ->
> /local/poky-multi/sources/git2_linuxtv.org.v4l-utils.git.tar.gz
> 
> After this change, they are not fetched from the network but seem to be
> copied from the mirror.  I just ran this sequence:
>   $ bitbake v4l-utils -c cleansstate
>   $ rm downloads/*v4l*
>   $ bitbake v4l-utils -c fetch
> which now shows
>   $ ls -l downloads/*v4l*
>   -rw-rw-r-- 1 gthomas gthomas 1439674 Jun 13 09:53
> downloads/git2_linuxtv.org.v4l-utils.git.tar.gz
> 
> I'll try to verify that the patch caused this change.

Indeed, the patch is not the cause of this difference.  Since it seems to be benign (still no network activity which is my main concern), I'm going to just note it but not worry about it.
Comment 11 Laurentiu Serban 2012-06-20 09:39:28 UTC
Verified