1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-23 02:32:13 +01:00

Fix pylint error: Using variable 'fd' before assignment

This commit is contained in:
Daniel Mach 2023-01-20 13:43:14 +01:00
parent b1e2a00b82
commit 7f885ac6b2
2 changed files with 12 additions and 5 deletions

View File

@ -2134,7 +2134,6 @@ class Package:
def diff_add_delete(fname, add, revision):
diff = []
diff.append(diff_hdr % fname.encode())
tmpfile = None
origname = fname
if add:
diff.append(b'--- %s\t(revision 0)\n' % fname.encode())
@ -2155,6 +2154,8 @@ class Package:
diff.append(b'+++ %s\t(working copy)\n' % fname.encode())
fname = os.path.join(self.storedir, fname)
fd = None
tmpfile = None
try:
if revision is not None and not add:
(fd, tmpfile) = tempfile.mkstemp(prefix='osc_diff')
@ -2180,8 +2181,9 @@ class Package:
lines.append(b'\n\\ No newline at end of file\n')
diff.extend(lines)
finally:
if tmpfile is not None:
if fd is not None:
os.close(fd)
if tmpfile is not None and os.path.exists(tmpfile):
os.unlink(tmpfile)
return diff
@ -2226,6 +2228,7 @@ class Package:
if revision is None:
yield get_source_file_diff(self.absdir, f.name, self.rev)
else:
fd = None
tmpfile = None
diff = []
try:
@ -2234,8 +2237,9 @@ class Package:
diff = get_source_file_diff(self.absdir, f.name, revision,
os.path.basename(tmpfile), os.path.dirname(tmpfile), f.name)
finally:
if tmpfile is not None:
if fd is not None:
os.close(fd)
if tmpfile is not None and os.path.exists(tmpfile):
os.unlink(tmpfile)
yield diff

View File

@ -86,6 +86,8 @@ class Fetcher:
pac = pkgs[decode_it(hdr.filename)]
# Extract a single file from the cpio archive
fd = None
tmpfile = None
try:
fd, tmpfile = tempfile.mkstemp(prefix='osc_build_file')
archive.copyin_file(hdr.filename,
@ -93,8 +95,9 @@ class Fetcher:
decode_it(os.path.basename(tmpfile)))
self.move_package(tmpfile, pac.localdir, pac)
finally:
os.close(fd)
if os.path.exists(tmpfile):
if fd is not None:
os.close(fd)
if tmpfile is not None and os.path.exists(tmpfile):
os.unlink(tmpfile)
for pac in pkgs.values():