test: fix cleanup order on provisioner daemon work dir (#9668)

* test: fix cleanup order on provisioner daemon work dir

* Reduce the test race condition
This commit is contained in:
Steven Masley
2023-09-13 13:13:08 -05:00
committed by GitHub
parent 53a985ff11
commit 0e4d6896e3
2 changed files with 16 additions and 2 deletions
+9
View File
@@ -230,6 +230,15 @@ func (s *Session) extractArchive() error {
if mode == 0 {
mode = 0o600
}
// Always check for context cancellation before reading the next header.
// This is mainly important for unit tests, since a canceled context means
// the underlying directory is going to be deleted. There still exists
// the small race condition that the context is cancelled after this, and
// before the disk write.
if ctx.Err() != nil {
return xerrors.Errorf("context canceled: %w", ctx.Err())
}
switch header.Typeflag {
case tar.TypeDir:
err = os.MkdirAll(headerPath, mode)