(diskPath string, fileNames []string)
| 36 | } |
| 37 | |
| 38 | func (util diskUtil) GetFilesContents(diskPath string, fileNames []string) ([][]byte, error) { |
| 39 | if !util.fs.FileExists(diskPath) { |
| 40 | return [][]byte{}, bosherr.Errorf("Failed to get file contents, disk path '%s' does not exist", diskPath) |
| 41 | } |
| 42 | |
| 43 | tempDir, err := util.fs.TempDir("diskutil") |
| 44 | if err != nil { |
| 45 | return [][]byte{}, bosherr.WrapError(err, "Creating temporary disk mount point") |
| 46 | } |
| 47 | |
| 48 | defer func() { |
| 49 | _ = util.fs.RemoveAll(tempDir) //nolint:errcheck |
| 50 | }() |
| 51 | |
| 52 | err = util.mounter.Mount(diskPath, tempDir) |
| 53 | if err != nil { |
| 54 | return [][]byte{}, bosherr.WrapErrorf(err, "Mounting disk path '%s' to '%s'", diskPath, tempDir) |
| 55 | } |
| 56 | |
| 57 | util.logger.Debug(util.logTag, "Mounted disk path '%s' to '%s'", diskPath, tempDir) |
| 58 | |
| 59 | contents := [][]byte{} |
| 60 | |
| 61 | for _, fileName := range fileNames { |
| 62 | diskFilePath := path.Join(tempDir, fileName) |
| 63 | |
| 64 | util.logger.Debug(util.logTag, "Reading contents of '%s'", diskFilePath) |
| 65 | |
| 66 | content, err := util.fs.ReadFile(diskFilePath) |
| 67 | if err != nil { |
| 68 | // todo unmount before removing |
| 69 | if uErr := util.unmount(tempDir); uErr != nil { |
| 70 | util.logger.Warn(util.logTag, "Failed to unmount temp dir: %s", uErr.Error()) |
| 71 | } |
| 72 | return [][]byte{}, bosherr.WrapErrorf(err, "Reading from disk file '%s'", diskFilePath) |
| 73 | } |
| 74 | |
| 75 | util.logger.Debug(util.logTag, "Got contents of %s: %s", diskFilePath, string(content)) |
| 76 | |
| 77 | contents = append(contents, content) |
| 78 | } |
| 79 | |
| 80 | err = util.unmount(tempDir) |
| 81 | if err != nil { |
| 82 | return [][]byte{}, err |
| 83 | } |
| 84 | |
| 85 | return contents, nil |
| 86 | } |
| 87 | |
| 88 | func (util diskUtil) GetBlockDeviceSize(diskPath string) (size uint64, err error) { |
| 89 | stdout, _, _, err := util.runner.RunCommand("lsblk", "--nodeps", "-nb", "-o", "SIZE", diskPath) |
nothing calls this directly
no test coverage detected