Skip to content

Commit

Permalink
Fix an error when attempting to delete the tmp dirs on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Dec 12, 2022
1 parent 69ad450 commit aaaee10
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions btest
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,12 @@ class Test(object):

if not success:
self.mgr.testSkipped(self)
if not Options.tmps:
if not self.mgr_data["Options"].tmps:
# Close these here, since the rm command in rmtmp will return an error on
# windows if the files are still open.
self.log.close()
self.stdout.close()
self.stderr.close()
self.rmTmp()
self.finish()
return
Expand Down Expand Up @@ -1207,6 +1212,11 @@ class Test(object):
self.mgr.testSucceeded(self)

if not self.mgr_data['Options'].tmps and self.reruns == 0:
# Close these here, since the rm command in rmtmp will return an error on
# windows if the files are still open.
self.log.close()
self.stdout.close()
self.stderr.close()
self.rmTmp()

self.finish()
Expand Down Expand Up @@ -1323,7 +1333,10 @@ class Test(object):
os.remove(self.tmpdir)

if os.path.isdir(self.tmpdir):
subprocess.call("rm -rf %s 2>/dev/null" % self.tmpdir, shell=True)
if sys.platform == 'win32':
subprocess.call(f"rm -rf {make_posix_path_from_windows(self.tmpdir)}", shell=True)
else:
subprocess.call(f"rm -rf {self.tmpdir} 2>/dev/null", shell=True)

except OSError as e:
error("cannot remove tmp directory %s: %s" % (self.tmpdir, e))
Expand Down

0 comments on commit aaaee10

Please sign in to comment.