summaryrefslogtreecommitdiff
path: root/0005-Fixes-for-exploded-SRPM-layouts.patch
blob: f2b57b3780af878e7fbc6d68fa8d3134893bd3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
From fc4dc6882c802e9a8b7ece3101033cb662928adf Mon Sep 17 00:00:00 2001
From: Troy Dawson <tdawson@redhat.com>
Date: Fri, 23 Sep 2022 14:38:34 -0700
Subject: [PATCH 1/2] Fixes for exploded SRPM layouts

sources_filename incorrectly set when using SRPMLayout.

Fixes: #633
JIRA: RHELCMP-9992
Merges: https://pagure.io/rpkg/pull-request/634

Signed-off-by: Troy Dawson <tdawson@redhat.com>
---
 pyrpkg/__init__.py    | 21 +++++++++++----------
 pyrpkg/cli.py         |  2 +-
 pyrpkg/sources.py     | 30 +++++++++++++++++++++++++-----
 tests/test_cli.py     |  2 +-
 tests/test_sources.py | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 1b6a0c4..a40fa5a 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -1153,7 +1153,8 @@ class Commands(object):
     def sources_filename(self):
         if self.layout is None:
             return os.path.join(self.path, 'sources')
-        return os.path.join(self.path, self.layout.sources_file_template)
+        return os.path.join(
+            self.path, self.layout.sources_file_template.replace("{0.repo_name}", self.repo_name))
 
     @property
     def osbs_config_filename(self):
@@ -2163,9 +2164,9 @@ class Commands(object):
             self.log.info("sources file doesn't exist. Source files download skipped.")
             return
 
-        # Default to putting the files where the repository is
+        # Default to putting the files in the layout sourcedir
         if not outdir:
-            outdir = self.path
+            outdir = self.layout.sourcedir
 
         sourcesf = SourcesFile(self.sources_filename, self.source_entry_type)
 
@@ -2578,7 +2579,7 @@ class Commands(object):
             cmd.append('--nocheck')
         if self.quiet:
             cmd.append('--quiet')
-        cmd.extend(['-bc', os.path.join(self.path, self.spec)])
+        cmd.extend(['-bc', os.path.join(self.layout.specdir, self.spec)])
         # Run the command
         self._run_command(cmd)
 
@@ -2657,7 +2658,7 @@ class Commands(object):
         if buildrootdir:
             cmd.extend(["--define", "_buildrootdir {0}".format(
                 os.path.abspath(buildrootdir))])
-        cmd.extend(['-bi', os.path.join(self.path, self.spec)])
+        cmd.extend(['-bi', os.path.join(self.layout.specdir, self.spec)])
         # Run the command
         self._run_command(cmd)
         return
@@ -2798,7 +2799,7 @@ class Commands(object):
         if not hashtype == 'sha256':
             cmd.extend(["--define", "_source_filedigest_algorithm %s" % hashtype,
                         "--define", "_binary_filedigest_algorithm %s" % hashtype])
-        specpath = os.path.join(self.path, self.spec)
+        specpath = os.path.join(self.layout.specdir, self.spec)
         tmpdir = None
         try:
             if not self.uses_rpmautospec or not rpmautospec_process_distgit:
@@ -3180,7 +3181,7 @@ class Commands(object):
         if buildrootdir:
             cmd.extend(["--define", "_buildrootdir {0}".format(
                 os.path.abspath(buildrootdir))])
-        cmd.extend(['--nodeps', '-bp', os.path.join(self.path, self.spec)])
+        cmd.extend(['--nodeps', '-bp', os.path.join(self.layout.specdir, self.spec)])
         # Run the command
         self._run_command(cmd)
 
@@ -3238,7 +3239,7 @@ class Commands(object):
         if not hashtype == 'sha256':
             cmd.extend(["--define", "_source_filedigest_algorithm %s" % hashtype,
                         "--define", "_binary_filedigest_algorithm %s" % hashtype])
-        specpath = os.path.join(self.path, self.spec)
+        specpath = os.path.join(self.layout.specdir, self.spec)
         tmpdir = None
         try:
             if not self.uses_rpmautospec or not rpmautospec_process_distgit:
@@ -3262,7 +3263,7 @@ class Commands(object):
         # Create a list for unused patches
         unused = []
         # Get the content of spec into memory for fast searching
-        with open(os.path.join(self.path, self.spec), 'r') as f:
+        with open(os.path.join(self.layout.specdir, self.spec), 'r') as f:
             data = f.read()
         if six.PY2:
             try:
@@ -3340,7 +3341,7 @@ class Commands(object):
         if buildrootdir:
             cmd.extend(["--define", "_buildrootdir {0}".format(
                 os.path.abspath(buildrootdir))])
-        cmd.extend(['-bl', os.path.join(self.path, self.spec)])
+        cmd.extend(['-bl', os.path.join(self.layout.specdir, self.spec)])
         # Run the command
         self._run_command(cmd)
 
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 9694f14..b0a16fb 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -1484,7 +1484,7 @@ class cliClient(object):
             'sources', help='Download source files',
             description='Download source files')
         sources_parser.add_argument(
-            '--outdir', default=os.curdir,
+            '--outdir',
             help='Directory to download files into (defaults to pwd)')
         sources_parser.set_defaults(command=self.sources)
 
diff --git a/pyrpkg/sources.py b/pyrpkg/sources.py
index 858461d..cdd5275 100644
--- a/pyrpkg/sources.py
+++ b/pyrpkg/sources.py
@@ -67,15 +67,35 @@ class SourcesFile(object):
             return self.entry_type(m.group('hashtype'), m.group('file'),
                                    m.group('hash'))
 
-        # Try falling back on the old format
+        # Try falling back on the old Fedora format
         try:
             hash, file = stripped.split('  ', 1)
 
         except ValueError:
-            raise MalformedLineError(
-                'sources has invalid content: {0}\n'
-                'Please note that sources file must not be modified manually.'
-                .format(stripped))
+            # Try old Centos Format
+            try:
+                hash, file_path = stripped.split(' ', 1)
+                if len(hash) == 128:
+                    hashtype = 'sha512'
+                elif len(hash) == 64:
+                    hashtype = 'sha256'
+                elif len(hash) == 40:
+                    hashtype = 'sha1'
+                elif len(hash) == 32:
+                    hashtype = 'md5'
+                else:
+                    raise MalformedLineError(
+                        'sources has invalid content: {0}\n'
+                        'Please note that sources file must not be modified manually.'
+                        .format(stripped))
+                file = os.path.split(file_path)[1]
+                return self.entry_type(hashtype, file, hash)
+
+            except ValueError:
+                raise MalformedLineError(
+                    'sources has invalid content: {0}\n'
+                    'Please note that sources file must not be modified manually.'
+                    .format(stripped))
 
         return self.entry_type('md5', file, hash)
 
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 97ae0ce..dd1399a 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1579,7 +1579,7 @@ class TestSources(LookasideCacheMock, CliTestCase):
         # NOTE: without --outdir, whatever to run sources command in package
         # repository, sources file is downloaded into current working
         # directory. Is this a bug, or need to improve?
-        self.assertTrue(os.path.exists('readme.patch'))
+        self.assertTrue(os.path.exists(os.path.join(self.cloned_repo_path, 'readme.patch')))
 
     def test_sources_to_outdir(self):
         cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
diff --git a/tests/test_sources.py b/tests/test_sources.py
index cfacc51..f041373 100644
--- a/tests/test_sources.py
+++ b/tests/test_sources.py
@@ -66,6 +66,39 @@ class SourcesFileTestCase(unittest.TestCase):
         self.assertEqual(entry.file, 'afile')
         self.assertEqual(str(entry), newline)
 
+    def test_parse_old_style_centos_line(self):
+        s = sources.SourcesFile(self.sourcesfile, 'old')
+
+        my_hash = 'abababab01010101010101010101010101010101'
+        my_file = 'SUBDIR/afile'
+
+        line = '{0} {1}\n'.format(my_hash, my_file)
+        newline = '{0}  {1}\n'.format(my_hash, 'afile')
+        entry = s.parse_line(line)
+
+        self.assertTrue(isinstance(entry, sources.SourceFileEntry))
+        self.assertEqual(entry.hashtype, 'sha1')
+        self.assertEqual(entry.hash, my_hash)
+        self.assertEqual(entry.file, 'afile')
+        self.assertEqual(str(entry), newline)
+
+    def test_migrate_old_style_centos_line(self):
+        s = sources.SourcesFile(self.sourcesfile, 'bsd')
+
+        my_hash = 128 * 'x'
+        my_file = 'SUBDIR/afile'
+
+        line = '{0} {1}\n'.format(my_hash, my_file)
+        newline = '{0}  {1}\n'.format(my_hash, 'afile')
+        newline = 'SHA512 (afile) = {0}\n'.format(my_hash)
+        entry = s.parse_line(line)
+
+        self.assertTrue(isinstance(entry, sources.SourceFileEntry))
+        self.assertEqual(entry.hashtype, 'sha512')
+        self.assertEqual(entry.hash, my_hash)
+        self.assertEqual(entry.file, 'afile')
+        self.assertEqual(str(entry), newline)
+
     def test_parse_entry_line(self):
         s = sources.SourcesFile(self.sourcesfile, 'bsd')
 
-- 
2.37.3