newFileFD creates a new file in a new tmpfs mount, and returns the FD. If the returned err is not nil, then cleanup should be called when the FD is no longer needed.
(ctx context.Context, mode linux.FileMode)
| 57 | // the returned err is not nil, then cleanup should be called when the FD is no |
| 58 | // longer needed. |
| 59 | func newFileFD(ctx context.Context, mode linux.FileMode) (*vfs.FileDescription, func(), error) { |
| 60 | creds := auth.CredentialsFromContext(ctx) |
| 61 | vfsObj, root, cleanup, err := newTmpfsRoot(ctx) |
| 62 | if err != nil { |
| 63 | return nil, nil, err |
| 64 | } |
| 65 | |
| 66 | filename := fmt.Sprintf("tmpfs-test-file-%d", nextFileID.Add(1)) |
| 67 | |
| 68 | // Create the file that will be write/read. |
| 69 | fd, err := vfsObj.OpenAt(ctx, creds, &vfs.PathOperation{ |
| 70 | Root: root, |
| 71 | Start: root, |
| 72 | Path: fspath.Parse(filename), |
| 73 | }, &vfs.OpenOptions{ |
| 74 | Flags: linux.O_RDWR | linux.O_CREAT | linux.O_EXCL, |
| 75 | Mode: linux.ModeRegular | mode, |
| 76 | }) |
| 77 | if err != nil { |
| 78 | cleanup() |
| 79 | return nil, nil, fmt.Errorf("failed to create file %q: %v", filename, err) |
| 80 | } |
| 81 | |
| 82 | return fd, cleanup, nil |
| 83 | } |
| 84 | |
| 85 | // newDirFD is like newFileFD, but for directories. |
| 86 | func newDirFD(ctx context.Context, mode linux.FileMode) (*vfs.FileDescription, func(), error) { |
no test coverage detected
searching dependent graphs…