Skip to content

Commit cf58531

Browse files
authored
fix: Ensure we restore the working directory upon failure (#1538)
1 parent cf99714 commit cf58531

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Box.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ public function endBuffering(?callable $dumpAutoload): void
156156
$this->scoper->getExcludedFilePaths(),
157157
);
158158

159-
chdir($cwd);
160-
161159
$unknownFiles = Finder::create()
162160
->files()
163161
->in($tmp)
@@ -176,6 +174,8 @@ public function endBuffering(?callable $dumpAutoload): void
176174
$this->phar->buildFromIterator(new ArrayIterator($files), $tmp);
177175
} finally {
178176
FS::remove($tmp);
177+
// Must happen _after_ the remove as the latter has higher priority.
178+
chdir($cwd);
179179
}
180180

181181
$this->buffering = false;

0 commit comments

Comments
 (0)