All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Ohly <patrick.ohly@intel.com>
To: Christopher Larson <clarson@kergoth.com>
Cc: Patches and discussions about the oe-core layer
	<openembedded-core@lists.openembedded.org>
Subject: Re: [PATCH] package_rpm.bbclass: support packaging of symlinks to directories
Date: Wed, 18 Feb 2015 10:08:06 +0100	[thread overview]
Message-ID: <1424250486.549.23.camel@intel.com> (raw)
In-Reply-To: <1424249010.549.15.camel@intel.com>

On Wed, 2015-02-18 at 09:43 +0100, Patrick Ohly wrote:
> On Tue, 2015-02-17 at 08:55 -0700, Christopher Larson wrote:
> > 
> > On Tue, Feb 17, 2015 at 6:42 AM, Patrick Ohly <patrick.ohly@intel.com>
> > wrote:
> >         +            # Treat all symlinks to directories as normal
> >         files.
> >         +            # os.walk() lists them as directories.
> >         +            for i, entry in enumerate(dirs):
> >         +                if os.path.islink(os.path.join(rootpath,
> >         entry)):
> >         +                    del dirs[i]
> >         +                    files.append(entry)
> >         +
> > 
> > You're deleting elements of a list while you're iterating over it. I'm
> > fairly certain that will lead to pain, unless you explicitly ensure
> > you're operating against a copy: for i, entry in
> > enumerate(list(dirs)):
> 
> I was wondering about that myself, but couldn't find any definite
> statement about whether it's okay or not for enumerate(). It works in
> practice, but of course that doesn't guarantee that it is okay.

The enumerate() documentation says that it is equivalent to a "for in"
loop, and documentation for that says "it is *recommended* that you
first make a copy" (emphasis mine). IMHO it means the behavior is simply
undefined.

> Iterating backwards will be more obviously correct, I'll send a patch
> update using that.

The recommended approach is using a slice copy
(https://docs.python.org/2/tutorial/controlflow.html#for-statements), so
how about this:

# Avoid modifying the list we iterate over, iterate over slice copy
# instead.
for i, entry in enumerate(dirs[:]):
    if os.path.islink(os.path.join(rootpath, entry)):
         del dirs[i]
         files.append(entry)

-- 
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.





  reply	other threads:[~2015-02-18  9:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-17 13:42 [PATCH] package_rpm.bbclass: support packaging of symlinks to directories Patrick Ohly
2015-02-17 15:55 ` Christopher Larson
2015-02-18  8:43   ` Patrick Ohly
2015-02-18  9:08     ` Patrick Ohly [this message]
2015-02-17 16:54 ` Mark Hatle
2015-02-17 16:57   ` Christopher Larson
2015-02-17 17:09     ` Mark Hatle
2015-02-18  3:40       ` Dan McGregor
2015-02-18  8:45         ` Patrick Ohly
2015-02-18 14:54           ` Mark Hatle
2015-02-25 14:51 ` [PATCH v2] " Patrick Ohly
2015-02-25 15:18   ` Patrick Ohly
2015-02-25 14:53 ` [PATCH v3] " Patrick Ohly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424250486.549.23.camel@intel.com \
    --to=patrick.ohly@intel.com \
    --cc=clarson@kergoth.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.