mirror of
https://git.yoctoproject.org/poky
synced 2026-05-09 17:39:31 +00:00
bitbake: fetch2: git: Use path_is_descendant() instead of path for repo check
Using path prefixes to check if the git directory is a descendant of the clone directory can be easily confused with symlinkes and bind mounts, causing directories to be deleted unnecessarily. Instead, use bb.utils.path_is_descendant() which is immune to the these sorts of problems. (Bitbake rev: b4d7a0546630620480b7fee159b84c3506e941a2) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
b2ab9bd4a3
commit
e12e6d94ec
@@ -373,20 +373,17 @@ class Git(FetchMethod):
|
|||||||
try:
|
try:
|
||||||
# Since clones can be bare, use --absolute-git-dir instead of --show-toplevel
|
# Since clones can be bare, use --absolute-git-dir instead of --show-toplevel
|
||||||
output = runfetchcmd("LANG=C %s rev-parse --absolute-git-dir" % ud.basecmd, d, workdir=ud.clonedir)
|
output = runfetchcmd("LANG=C %s rev-parse --absolute-git-dir" % ud.basecmd, d, workdir=ud.clonedir)
|
||||||
|
toplevel = output.rstrip()
|
||||||
|
|
||||||
toplevel = os.path.abspath(output.rstrip())
|
if not bb.utils.path_is_descendant(toplevel, ud.clonedir):
|
||||||
abs_clonedir = os.path.abspath(ud.clonedir).rstrip('/')
|
logger.warning("Top level directory '%s' is not a descendant of '%s'. Re-cloning", toplevel, ud.clonedir)
|
||||||
# The top level Git directory must either be the clone directory
|
|
||||||
# or a child of the clone directory. Any ancestor directory of
|
|
||||||
# the clone directory is not valid as the Git directory (and
|
|
||||||
# probably belongs to some other unrelated repository), so a
|
|
||||||
# clone is required
|
|
||||||
if os.path.commonprefix([abs_clonedir, toplevel]) != abs_clonedir:
|
|
||||||
logger.warning("Top level directory '%s' doesn't match expected '%s'. Re-cloning", toplevel, ud.clonedir)
|
|
||||||
needs_clone = True
|
needs_clone = True
|
||||||
except bb.fetch2.FetchError as e:
|
except bb.fetch2.FetchError as e:
|
||||||
logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e)
|
logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e)
|
||||||
needs_clone = True
|
needs_clone = True
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
logger.warning("%s", e)
|
||||||
|
needs_clone = True
|
||||||
|
|
||||||
if needs_clone:
|
if needs_clone:
|
||||||
shutil.rmtree(ud.clonedir)
|
shutil.rmtree(ud.clonedir)
|
||||||
|
|||||||
Reference in New Issue
Block a user