lib/oeqa/decorators: handle broken links when creating new symlink

Message ID 1469196210-29675-1-git-send-email-ross.burton@intel.com
State Accepted
Commit ec24b6de2b8686e1f779fef3a963e66f70eeba74
Headers show

Commit Message

Ross Burton July 22, 2016, 2:03 p.m.
When checking if a link exists before creating it, use os.path.lexists() as
otherwise os.path.exists() on a broken link will return False.

Signed-off-by: Ross Burton <ross.burton@intel.com>

---
 meta/lib/oeqa/utils/decorators.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.8.1

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Comments

Khem Raj July 22, 2016, 2:13 p.m. | #1
On Fri, Jul 22, 2016 at 7:03 AM, Ross Burton <ross.burton@intel.com> wrote:
> When checking if a link exists before creating it, use os.path.lexists() as

> otherwise os.path.exists() on a broken link will return False.

>

> Signed-off-by: Ross Burton <ross.burton@intel.com>

> ---

>  meta/lib/oeqa/utils/decorators.py | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

>

> diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py

> index 0b23565..615fd95 100644

> --- a/meta/lib/oeqa/utils/decorators.py

> +++ b/meta/lib/oeqa/utils/decorators.py

> @@ -190,7 +190,7 @@ def LogResults(original_class):

>              local_log.results("Testcase "+str(test_case)+": PASSED")

>

>          # Create symlink to the current log

> -        if os.path.exists(linkfile):

> +        if os.path.lexists(linkfile):


I think it will fail if the existing file is not a symlink ?

>              os.remove(linkfile)

>          os.symlink(logfile, linkfile)

>

> --

> 2.8.1

>

> --

> _______________________________________________

> Openembedded-core mailing list

> Openembedded-core@lists.openembedded.org

> http://lists.openembedded.org/mailman/listinfo/openembedded-core

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Ross Burton July 22, 2016, 3:11 p.m. | #2
On 22 July 2016 at 15:13, Khem Raj <raj.khem@gmail.com> wrote:

> I think it will fail if the existing file is not a symlink ?

>


No, the only difference between lexists and exists is that exists follows
links.  So in the case of a broken link, exists returns false.

Ross
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Khem Raj July 22, 2016, 3:41 p.m. | #3
Yes ok

On Jul 22, 2016 8:11 AM, "Burton, Ross" <ross.burton@intel.com> wrote:

>

> On 22 July 2016 at 15:13, Khem Raj <raj.khem@gmail.com> wrote:

>

>> I think it will fail if the existing file is not a symlink ?

>>

>

> No, the only difference between lexists and exists is that exists follows

> links.  So in the case of a broken link, exists returns false.

>

> Ross

>

>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Patch

diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 0b23565..615fd95 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -190,7 +190,7 @@  def LogResults(original_class):
             local_log.results("Testcase "+str(test_case)+": PASSED")
 
         # Create symlink to the current log
-        if os.path.exists(linkfile):
+        if os.path.lexists(linkfile):
             os.remove(linkfile)
         os.symlink(logfile, linkfile)