mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-10 13:05:46 +01:00
Use with statement in CpioRead._copyin_file
This makes sure that the file is closed in case of an exception.
This commit is contained in:
parent
5387744d36
commit
e60af6f120
@ -124,11 +124,10 @@ class CpioRead:
|
|||||||
if not stat.S_ISREG(stat.S_IFMT(hdr.mode)):
|
if not stat.S_ISREG(stat.S_IFMT(hdr.mode)):
|
||||||
msg = '\'%s\' is no regular file - only regular files are supported atm' % hdr.filename
|
msg = '\'%s\' is no regular file - only regular files are supported atm' % hdr.filename
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
fn = os.path.join(dest, fn)
|
|
||||||
f = open(fn, 'wb')
|
|
||||||
self.__file.seek(hdr.dataoff, os.SEEK_SET)
|
self.__file.seek(hdr.dataoff, os.SEEK_SET)
|
||||||
|
fn = os.path.join(dest, fn)
|
||||||
|
with open(fn, 'wb') as f:
|
||||||
f.write(self.__file.read(hdr.filesize))
|
f.write(self.__file.read(hdr.filesize))
|
||||||
f.close()
|
|
||||||
os.chmod(fn, hdr.mode)
|
os.chmod(fn, hdr.mode)
|
||||||
uid = hdr.uid
|
uid = hdr.uid
|
||||||
if uid != os.geteuid() or os.geteuid() != 1:
|
if uid != os.geteuid() or os.geteuid() != 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user