From b0cf5048340db93853ae43531fd8c8ec23b61b2e Mon Sep 17 00:00:00 2001
From: Andrej Shadura <andrew.shadura@collabora.co.uk>
Date: Fri, 13 May 2022 15:54:10 +0200
Subject: [PATCH 1/3] Test that removing files referenced in .dsc causes no
 issues on re-upload

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
---
 .gitlab-ci.yml | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a9ce500..cc56e35 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -71,6 +71,13 @@ test:
   - cd ../..
   - osc --debug dput "$PROJECT" _build/*changes | tee log
   - grep -q "Committed revision" log && echo "Commit as expected"
+  - ": Remove the tarball and then try to re-upload"
+  - cd "$PROJECT/$PACKAGE"
+  - osc up
+  - osc rm *.tar.xz
+  - osc --debug commit -m "delete tarball"
+  - cd ../..
+  - osc --debug dput "$PROJECT" _build/*changes | tee log
   - ": Verify we can replace a package completely"
   - osc co "$ORIG_PROJECT" "$TEST_PACKAGE"
   - cd "$PROJECT/$PACKAGE"
-- 
GitLab


From ac0e27af6a172e2af8e5c9be22dd24e153e16396 Mon Sep 17 00:00:00 2001
From: Andrej Shadura <andrew.shadura@collabora.co.uk>
Date: Fri, 13 May 2022 15:56:29 +0200
Subject: [PATCH 2/3] Only mark existent remote files as superseded

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
---
 osc_plugin_dput/main.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/osc_plugin_dput/main.py b/osc_plugin_dput/main.py
index 40bf8fb..29e107a 100644
--- a/osc_plugin_dput/main.py
+++ b/osc_plugin_dput/main.py
@@ -205,7 +205,8 @@ def do_dput(self, subcmd, opts, *args):
                 remote_dsc = Dsc(osc.core.streamfile(u, bufsize='line'))
 
                 for entry in remote_dsc.get('Files'):
-                    superseded.add(entry['name'])
+                    if entry['name'] in remote_file_list:
+                        superseded.add(entry['name'])
 
                 superseded.add(f)
             elif f.endswith('.changes'):
-- 
GitLab


From 19f0903204e1d47774d84ab7f5c458f69ef574ad Mon Sep 17 00:00:00 2001
From: Andrej Shadura <andrew.shadura@collabora.co.uk>
Date: Fri, 13 May 2022 15:56:48 +0200
Subject: [PATCH 3/3] Drop dead and unused code

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
---
 osc_plugin_dput/main.py | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/osc_plugin_dput/main.py b/osc_plugin_dput/main.py
index 29e107a..1ff6ed8 100644
--- a/osc_plugin_dput/main.py
+++ b/osc_plugin_dput/main.py
@@ -191,7 +191,6 @@ def do_dput(self, subcmd, opts, *args):
         # Remove old files, but only those that are part of the Debian package
         superseded = set()
         retained = set()
-        downloaded = set()
 
         for f in remote_file_list.keys():
             if f.endswith('.dsc'):
@@ -233,7 +232,7 @@ def do_dput(self, subcmd, opts, *args):
         os.symlink(dsc_file, f)
         package.addfile(f)
 
-        if opts.maintained_in_git and 'MAINTAINED_IN_GIT.txt' not in retained:
+        if opts.maintained_in_git:
             open('MAINTAINED_IN_GIT.txt', 'w+').close()
             package.addfile('MAINTAINED_IN_GIT.txt')
 
@@ -242,9 +241,6 @@ def do_dput(self, subcmd, opts, *args):
         # the source package
         msg = f
 
-        for f in downloaded:
-            package.addfile(f)
-
         if changes is not None:
             f = dsc_or_changes_file.name
             os.symlink(dsc_or_changes_file, f)
-- 
GitLab