Skip to content

Commit

Permalink
urlscm: remove downloaded files on ATTIC move
Browse files Browse the repository at this point in the history
Delete the download directory if the scm-workspace is moved to attic.
  • Loading branch information
rhubert committed Jan 21, 2025
1 parent 3f349d3 commit 3c2f057
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pym/bob/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,8 @@ async def _cookCheckoutStep(self, checkoutStep, depth):
os.makedirs(atticPath)
atticPath = os.path.join(atticPath, atticName)
os.rename(scmPath, atticPath)
if scmDir in scmMap:
scmMap[scmDir].postAttic(prettySrcPath)
BobState().setAtticDirectoryState(atticPath, scmSpec)
atticPaths.add(scmPath, atticPath)
del oldCheckoutState[scmDir]
Expand Down
3 changes: 3 additions & 0 deletions pym/bob/scm/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ def calcLiveBuildId(self, workspacePath):
"""Calculate live build-id from workspace."""
return None

def postAttic(self, workspace):
pass

class ScmAudit(metaclass=ABCMeta):
@classmethod
async def fromDir(cls, workspace, dir, extra):
Expand Down
6 changes: 6 additions & 0 deletions pym/bob/scm/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,12 @@ def __getExtractor(self):
raise ParseError("Invalid extract mode: " + self.__extract)
return extractor

def postAttic(self, workspace):
if self.__separateDownload:
# os.path.exists returns False if os.pardir is in the path -> normalize it
downloadDestination = os.path.normpath(os.path.join(workspace, os.pardir, "download", self.__dir))
if os.path.exists(downloadDestination):
shutil.rmtree(downloadDestination)

class UrlAudit(ScmAudit):

Expand Down
2 changes: 1 addition & 1 deletion test/black-box/url-scm-switch/config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bobMinimumVersion: "0.17.3.dev82"
bobMinimumVersion: "0.25.1.dev32"
14 changes: 14 additions & 0 deletions test/black-box/url-scm-switch/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
. ../../test-lib.sh 2>/dev/null || { echo "Must run in script directory!" ; exit 1 ; }
cleanup

tempdir=$(mktemp -d)
trap 'rm -rf "${tempdir}"' EXIT

url="$(mangle_path "$(realpath file.txt)")"
url2="$(mangle_path "$(realpath file2.txt)")"

tar -cvzf $tempdir/file.tgz file.txt
tar -cvzf $tempdir/file2.tgz file2.txt

# Build and fetch result path
run_bob dev root -DURL="$url"
path=$(run_bob query-path -DURL="$url" -f {src} root)
Expand Down Expand Up @@ -36,3 +42,11 @@ run_bob dev root -DURL="$url2"
expect_not_exist "$path/file.txt"
expect_not_exist "$path/canary.txt"
diff -q "$path/file2.txt" file2.txt

cleanup
run_bob dev root -DURL="$tempdir/file.tgz"
expect_exist $path/../download/file.tgz

run_bob dev root -DURL="$tempdir/file2.tgz"
expect_exist $path/../download/file2.tgz
expect_not_exist $path/../download/file.tgz

0 comments on commit 3c2f057

Please sign in to comment.