* [PATCH] bitbake: Correct broken symlink behaviour
@ 2016-09-20 16:23 Roman Savchenko
2016-09-21 21:17 ` Richard Purdie
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Roman Savchenko @ 2016-09-20 16:23 UTC (permalink / raw)
To: bitbake-devel
From: Roman Savchenko <roman.savchenko@attocapital.com>
Unlink broken symlink.
Signed-off-by: Roman Savchenko <gmstima@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..a752c6c 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.
+ """
+ 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] bitbake: Correct broken symlink behaviour
2016-09-20 16:23 [PATCH] bitbake: Correct broken symlink behaviour Roman Savchenko
@ 2016-09-21 21:17 ` Richard Purdie
2016-09-23 7:45 ` Roman Savchenko
2016-09-27 10:22 ` Roman Savchenko
2 siblings, 0 replies; 7+ messages in thread
From: Richard Purdie @ 2016-09-21 21:17 UTC (permalink / raw)
To: Roman Savchenko, bitbake-devel
Hi,
On Tue, 2016-09-20 at 19:23 +0300, Roman Savchenko wrote:
> From: Roman Savchenko <roman.savchenko@attocapital.com>
>
> Unlink broken symlink.
This really needs a few more details about the problem and how an issue
occurs. I can understand from reading the patch but not from the commit
message.
> Signed-off-by: Roman Savchenko <gmstima@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..a752c6c 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.
> + """
> + if not os.path.exists(link_name):
> + if os.path.islink(link_name):
> + os.unlink(link_name)
> +
> + os.symlink(source, link_name)
> +
I don't think the function name is right. "try" implies its fine if it
doesn't work out. In reality its more like "symlink if its invalid".
"create_valid_symlink" whilst long is probably more reflective of what
it does but I'm sure we could still do better :/.
You could add "or the symlink is invalid" to the function description
too.
Cheers,
Richard
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] bitbake: Correct broken symlink behaviour
2016-09-20 16:23 [PATCH] bitbake: Correct broken symlink behaviour Roman Savchenko
2016-09-21 21:17 ` Richard Purdie
@ 2016-09-23 7:45 ` Roman Savchenko
2016-09-23 7:55 ` Roman Savchenko
2016-09-27 10:22 ` Roman Savchenko
2 siblings, 1 reply; 7+ messages in thread
From: Roman Savchenko @ 2016-09-23 7:45 UTC (permalink / raw)
To: bitbake-devel
From: Roman Savchenko <roman.savchenko@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@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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] bitbake: Correct broken symlink behaviour
2016-09-23 7:45 ` Roman Savchenko
@ 2016-09-23 7:55 ` Roman Savchenko
2016-09-23 14:01 ` Richard Purdie
0 siblings, 1 reply; 7+ messages in thread
From: Roman Savchenko @ 2016-09-23 7:55 UTC (permalink / raw)
To: bitbake-devel
[-- Attachment #1: Type: text/plain, Size: 2768 bytes --]
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@gmail.com>:
> From: Roman Savchenko <roman.savchenko@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@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
>
>
[-- Attachment #2: Type: text/html, Size: 3882 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] bitbake: Correct broken symlink behaviour
2016-09-23 7:55 ` Roman Savchenko
@ 2016-09-23 14:01 ` Richard Purdie
0 siblings, 0 replies; 7+ messages in thread
From: Richard Purdie @ 2016-09-23 14:01 UTC (permalink / raw)
To: Roman Savchenko, bitbake-devel
Hi Roman,
On Fri, 2016-09-23 at 10:55 +0300, Roman Savchenko wrote:
> 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.
I don't agree with "try_symlink" though, sorry.
Link creation can fail but that is like any other function which can
also fail. We don't prefix all function names with try_ because they
can fail.
We need a better name.
Cheers,
Richard
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] bitbake: Correct broken symlink behaviour
2016-09-20 16:23 [PATCH] bitbake: Correct broken symlink behaviour Roman Savchenko
2016-09-21 21:17 ` Richard Purdie
2016-09-23 7:45 ` Roman Savchenko
@ 2016-09-27 10:22 ` Roman Savchenko
2016-09-27 10:24 ` Roman Savchenko
2 siblings, 1 reply; 7+ messages in thread
From: Roman Savchenko @ 2016-09-27 10:22 UTC (permalink / raw)
To: bitbake-devel
From: Roman Savchenko <roman.savchenko@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@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..6638b34 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 create_symlink_if_not_exist(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)
+ create_symlink_if_not_exist(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)
+ create_symlink_if_not_exist(ud.localpath, origud.localpath)
update_stamp(origud, ld)
return ud.localpath
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] bitbake: Correct broken symlink behaviour
2016-09-27 10:22 ` Roman Savchenko
@ 2016-09-27 10:24 ` Roman Savchenko
0 siblings, 0 replies; 7+ messages in thread
From: Roman Savchenko @ 2016-09-27 10:24 UTC (permalink / raw)
To: bitbake-devel
[-- Attachment #1: Type: text/plain, Size: 2699 bytes --]
Hi Richard,
I renamed function, probably name is a little bit long, but it fully
displays what it does.
Regards,
Roman.
2016-09-27 13:22 GMT+03:00 Roman Savchenko <gmstima@gmail.com>:
> From: Roman Savchenko <roman.savchenko@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@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..6638b34 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 create_symlink_if_not_exist(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)
> + create_symlink_if_not_exist(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)
> + create_symlink_if_not_exist(ud.localpath, origud.localpath)
> update_stamp(origud, ld)
> return ud.localpath
>
> --
> 2.7.4
>
>
[-- Attachment #2: Type: text/html, Size: 3739 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-09-27 10:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-20 16:23 [PATCH] bitbake: Correct broken symlink behaviour Roman Savchenko
2016-09-21 21:17 ` Richard Purdie
2016-09-23 7:45 ` Roman Savchenko
2016-09-23 7:55 ` Roman Savchenko
2016-09-23 14:01 ` Richard Purdie
2016-09-27 10:22 ` Roman Savchenko
2016-09-27 10:24 ` Roman Savchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.