|
19 | 19 | package loopback |
20 | 20 |
|
21 | 21 | import ( |
| 22 | + "bytes" |
22 | 23 | "io/ioutil" |
23 | 24 | "os" |
24 | 25 | "os/exec" |
@@ -46,22 +47,25 @@ func New(size int64) (*Loopback, error) { |
46 | 47 |
|
47 | 48 | // create device |
48 | 49 | losetup := exec.Command("losetup", "--find", "--show", file.Name()) |
49 | | - p, err := losetup.Output() |
50 | | - if err != nil { |
| 50 | + var stdout, stderr bytes.Buffer |
| 51 | + losetup.Stdout = &stdout |
| 52 | + losetup.Stderr = &stderr |
| 53 | + if err := losetup.Run(); err != nil { |
51 | 54 | os.Remove(file.Name()) |
52 | | - return nil, errors.Wrap(err, "loopback setup failed") |
| 55 | + return nil, errors.Wrapf(err, "loopback setup failed (%v): stdout=%q, stderr=%q", |
| 56 | + losetup.Args, stdout.String(), stderr.String()) |
53 | 57 | } |
54 | 58 |
|
55 | | - deviceName := strings.TrimSpace(string(p)) |
| 59 | + deviceName := strings.TrimSpace(stdout.String()) |
56 | 60 | logrus.Debugf("Created loop device %s (using %s)", deviceName, file.Name()) |
57 | 61 |
|
58 | 62 | cleanup := func() error { |
59 | 63 | // detach device |
60 | 64 | logrus.Debugf("Removing loop device %s", deviceName) |
61 | 65 | losetup := exec.Command("losetup", "--detach", deviceName) |
62 | | - err := losetup.Run() |
63 | | - if err != nil { |
64 | | - return errors.Wrapf(err, "Could not remove loop device %s", deviceName) |
| 66 | + if out, err := losetup.CombinedOutput(); err != nil { |
| 67 | + return errors.Wrapf(err, "Could not remove loop device %s (%v): %q", |
| 68 | + deviceName, losetup.Args, string(out)) |
65 | 69 | } |
66 | 70 |
|
67 | 71 | // remove file |
|
0 commit comments