Skip to content

Commit

Permalink
Fix pylint error: Using variable 'fd' before assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jan 20, 2023
1 parent b1e2a00 commit 7f885ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,6 @@ def get_diff(self, revision=None, ignoreUnversioned=False):
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())
Expand All @@ -2155,6 +2154,8 @@ def diff_add_delete(fname, add, revision):
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')
Expand All @@ -2180,8 +2181,9 @@ def diff_add_delete(fname, add, revision):
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

Expand Down Expand Up @@ -2226,6 +2228,7 @@ def diff_add_delete(fname, add, revision):
if revision is None:
yield get_source_file_diff(self.absdir, f.name, self.rev)
else:
fd = None
tmpfile = None
diff = []
try:
Expand All @@ -2234,8 +2237,9 @@ def diff_add_delete(fname, add, revision):
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

Expand Down
7 changes: 5 additions & 2 deletions osc/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ def __download_cpio_archive(self, apiurl, project, repo, arch, package, **pkgs):
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,
decode_it(os.path.dirname(tmpfile)),
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():
Expand Down

0 comments on commit 7f885ac

Please sign in to comment.