Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/sentry/fsimpl/tmpfs/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ func (fs *filesystem) readFromTar(ctx context.Context, tr *tar.Reader) error {
if n != header.Size {
return fmt.Errorf("failed to read all file content, got %d bytes, want %d", n, header.Size)
}
if header.Size > 0 {
fileToContent[header.Name] = &buffer
}
fileToHeader[header.Name] = header
fileToContent[header.Name] = &buffer
case tar.TypeFifo, tar.TypeBlock, tar.TypeChar:
fileToHeader[header.Name] = header
case tar.TypeSymlink:
Expand Down
3 changes: 1 addition & 2 deletions runsc/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4035,11 +4035,10 @@ func TestTarRootfsUpperLayer(t *testing.T) {
if err := cont.Start(conf); err != nil {
t.Fatalf("error starting container: %v", err)
}

// Exec the command in the container.
execArgs := &control.ExecArgs{
Filename: app,
Argv: []string{app, "fsTreeCreate", "--depth=3", "--file-per-level=2", "--file-size=1470", "--create-symlink"},
Argv: []string{app, "fsTreeCreate", "--depth=3", "--file-per-level=2", "--file-size=1470", "--create-symlink", "--add-empty-files"},
}
if ws, err := cont.executeSync(conf, execArgs); err != nil {
t.Fatalf("error exec'ing: %v", err)
Expand Down
8 changes: 8 additions & 0 deletions test/cmd/test_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type fsTreeCreator struct {
fileSize uint
targetDir string
createSymlink bool
addEmptyFiles bool
}

// Name implements subcommands.Command.Name.
Expand All @@ -91,6 +92,7 @@ func (c *fsTreeCreator) SetFlags(f *flag.FlagSet) {
f.UintVar(&c.fileSize, "file-size", 4096, "size of each file")
f.StringVar(&c.targetDir, "target-dir", "/", "directory under which to create the filesystem tree")
f.BoolVar(&c.createSymlink, "create-symlink", false, "create symlinks other than the first file per level")
f.BoolVar(&c.addEmptyFiles, "add-empty-files", false, "add empty file to each level")
}

// Execute implements subcommands.Command.Execute.
Expand All @@ -117,6 +119,12 @@ func (c *fsTreeCreator) Execute(ctx context.Context, f *flag.FlagSet, args ...an
}
}
}
if c.addEmptyFiles {
emptyPath := filepath.Join(curDir, fmt.Sprintf("empty%d", i))
if err := os.WriteFile(emptyPath, nil, 0666); err != nil {
log.Fatalf("error writing empty file %q: %v", emptyPath, err)
}
}
nextDir := filepath.Join(curDir, "dir")
if err := os.Mkdir(nextDir, 0777); err != nil {
log.Fatalf("error creating directory %q: %v", nextDir, err)
Expand Down