mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
* Move task directory destroy logic from alloc_dir to task_dir * Update errors to wrap error cause * Use constants for file permissions * Make multierror handling consistent. * Make helpers for directory creation * Move mount dir unlink to task_dir Unlink method * Make constant for file mode 710 Co-authored-by: Tim Gross <tgross@hashicorp.com> Co-authored-by: Michael Schurter <mschurter@hashicorp.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package allocdir
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
|
)
|
|
|
|
// unmountSpecialDirs unmounts the dev and proc file system from the chroot. No
|
|
// error is returned if the directories do not exist or have already been
|
|
// unmounted.
|
|
func (t *TaskDir) unmountSpecialDirs() error {
|
|
mErr := new(multierror.Error)
|
|
dev := filepath.Join(t.Dir, "dev")
|
|
if pathExists(dev) {
|
|
if err := unlinkDir(dev); err != nil {
|
|
mErr = multierror.Append(mErr, fmt.Errorf("Failed to unmount dev %q: %w", dev, err))
|
|
} else if err := os.RemoveAll(dev); err != nil {
|
|
mErr = multierror.Append(mErr, fmt.Errorf("Failed to delete dev directory %q: %w", dev, err))
|
|
}
|
|
}
|
|
|
|
// Unmount proc.
|
|
proc := filepath.Join(t.Dir, "proc")
|
|
if pathExists(proc) {
|
|
if err := unlinkDir(proc); err != nil {
|
|
mErr = multierror.Append(mErr, fmt.Errorf("Failed to unmount proc %q: %w", proc, err))
|
|
} else if err := os.RemoveAll(proc); err != nil {
|
|
mErr = multierror.Append(mErr, fmt.Errorf("Failed to delete proc directory %q: %w", dev, err))
|
|
}
|
|
}
|
|
|
|
return mErr.ErrorOrNil()
|
|
}
|