[bitbake-devel] [PATCH] bitbake: Correct broken symlink behaviour

Roman Savchenko gmstima at gmail.com
Fri Sep 23 07:55:10 UTC 2016


Hi Richard,

I adjusted commit message and function description. but I do not agree with
proposed
function name `create_valid_symlink`, becasue link creation could fail - so
I left `try_symlink`
to point this behaviour.

Regards,
Roman

2016-09-23 10:45 GMT+03:00 Roman Savchenko <gmstima at gmail.com>:

> From: Roman Savchenko <roman.savchenko at attocapital.com>
>
> When making new symlink in case when link name does not exist
> possible broken symlink behaviour should be taken into account.
>
> Signed-off-by: Roman Savchenko <gmstima at gmail.com>
> ---
>  bitbake/lib/bb/fetch2/__init__.py | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__
> init__.py
> index 6ef0c6f..d8a3b96 100644
> --- a/bitbake/lib/bb/fetch2/__init__.py
> +++ b/bitbake/lib/bb/fetch2/__init__.py
> @@ -925,6 +925,17 @@ def rename_bad_checksum(ud, suffix):
>      bb.utils.movefile(ud.localpath, new_localpath)
>
>
> +def try_symlink(source, link_name):
> +    """
> +    Tries to make link to passed source if link name does not
> +    exist or it is the invalid symlink.
> +    """
> +    if not os.path.exists(link_name):
> +        if os.path.islink(link_name):
> +            os.unlink(link_name)
> +
> +        os.symlink(source, link_name)
> +
>  def try_mirror_url(fetch, origud, ud, ld, check = False):
>      # Return of None or a value means we're finished
>      # False means try another url
> @@ -962,20 +973,14 @@ def try_mirror_url(fetch, origud, ud, ld, check =
> False):
>                  bb.utils.mkdirhier(os.path.dirname(ud.donestamp))
>                  open(ud.donestamp, 'w').close()
>              dest = os.path.join(dldir, os.path.basename(ud.localpath))
> -            if not os.path.exists(dest):
> -                os.symlink(ud.localpath, dest)
> +            try_symlink(ud.localpath, dest)
>              if not verify_donestamp(origud, ld) or
> origud.method.need_update(origud, ld):
>                  origud.method.download(origud, ld)
>                  if hasattr(origud.method,"build_mirror_data"):
>                      origud.method.build_mirror_data(origud, ld)
>              return origud.localpath
>          # Otherwise the result is a local file:// and we symlink to it
> -        if not os.path.exists(origud.localpath):
> -            if os.path.islink(origud.localpath):
> -                # Broken symbolic link
> -                os.unlink(origud.localpath)
> -
> -            os.symlink(ud.localpath, origud.localpath)
> +        try_symlink(ud.localpath, origud.localpath)
>          update_stamp(origud, ld)
>          return ud.localpath
>
> --
> 2.7.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/bitbake-devel/attachments/20160923/dabc38b0/attachment-0002.html>


More information about the bitbake-devel mailing list