aptly_deb_usage: Remove file folders before upload packages

In corner cases when file been uploaded into file folder but not
inserted into repo and clean the file folder, the process been
interrupted thus the file fold with packages been remained by
mistake. This will cause the uploaded package been placed into
wrong repository. To fix it:
Each time before upload package, remove file folders;
Each repository use its own file folder as its name.

Test Plan:
  - PASS: repo_manage.py upload_pkg ...

Story: 2009221
Task: 44959

Signed-off-by: ZhangXiao <xiao.zhang@windriver.com>
Change-Id: Id680b1071e6a001b01d394bc613389cd41d3c682
This commit is contained in:
ZhangXiao 2022-04-06 15:57:21 +08:00
parent 81e5f92b68
commit afe3b76e6f

View File

@ -471,9 +471,14 @@ class Deb_aptly():
# with '%3a' by mistake, this will cause error in aptly.
new_name = pkg_name.replace('%3a', ':')
os.rename(pkg_name, new_name)
# Add the package into local repo
self.aptly.files.upload('tmp_folder', new_name)
task = self.aptly.repos.add_uploaded_file(repo_name, 'tmp_folder', remove_processed_files=True)
# In corner cases the process been interrupted thus related file folders
# remained. Remove them firstly.
for file in self.aptly.files.list():
self.aptly.files.delete(file)
# Upload package file into related file folder.
self.aptly.files.upload(repo_name, new_name)
# Add uploaded file into local repository.
task = self.aptly.repos.add_uploaded_file(repo_name, repo_name, remove_processed_files=True)
self.aptly.tasks.wait_for_task_by_id(task.id)
if self.aptly.tasks.show(task.id).state != 'SUCCEEDED':
self.logger.warning('add_upload_file failed %s : %s : %s', new_name, repo_name, self.aptly.tasks.show(task.id).state)