Skip to content

Commit

Permalink
Rename tarwriter.WriteNode to tarwriter.WriteFile
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Aug 6, 2024
1 parent 7371b76 commit 4f392d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions files/tarwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (w *TarWriter) writeDir(f Directory, fpath string) error {

it := f.Entries()
for it.Next() {
if err := w.WriteNode(it.Node(), path.Join(fpath, it.Name())); err != nil {
if err := w.WriteFile(it.Node(), path.Join(fpath, it.Name())); err != nil {
return err
}
}
Expand Down Expand Up @@ -78,8 +78,8 @@ func validateTarFilePath(baseDir, fpath string) bool {
return true
}

// WriteNode adds a node to the archive.
func (w *TarWriter) WriteNode(nd Node, fpath string) error {
// WriteFile adds a node to the archive.
func (w *TarWriter) WriteFile(nd Node, fpath string) error {
if !w.baseDirSet {
w.baseDirSet = true // Use a variable for this as baseDir may be an empty string.
w.baseDir = fpath
Expand Down
8 changes: 4 additions & 4 deletions files/tarwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestTarWriter(t *testing.T) {

go func() {
defer tw.Close()
if err := tw.WriteNode(tf, ""); err != nil {
if err := tw.WriteFile(tf, ""); err != nil {
t.Error(err)
}
}()
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestTarWriterRelativePathInsideRoot(t *testing.T) {
}

defer tw.Close()
if err = tw.WriteNode(tf, ""); err != nil {
if err = tw.WriteFile(tf, ""); err != nil {
t.Error(err)
}
}
Expand All @@ -137,7 +137,7 @@ func TestTarWriterFailsFileOutsideRoot(t *testing.T) {
}

defer tw.Close()
if err = tw.WriteNode(tf, ""); !errors.Is(err, ErrUnixFSPathOutsideRoot) {
if err = tw.WriteFile(tf, ""); !errors.Is(err, ErrUnixFSPathOutsideRoot) {
t.Errorf("unexpected error, wanted: %v; got: %v", ErrUnixFSPathOutsideRoot, err)
}
}
Expand All @@ -158,7 +158,7 @@ func TestTarWriterFailsFileOutsideRootWithBaseDir(t *testing.T) {
}

defer tw.Close()
if err = tw.WriteNode(tf, "test.tar"); !errors.Is(err, ErrUnixFSPathOutsideRoot) {
if err = tw.WriteFile(tf, "test.tar"); !errors.Is(err, ErrUnixFSPathOutsideRoot) {
t.Errorf("unexpected error, wanted: %v; got: %v", ErrUnixFSPathOutsideRoot, err)
}
}
2 changes: 1 addition & 1 deletion gateway/handler_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (i *handler) serveTAR(ctx context.Context, w http.ResponseWriter, r *http.R
w.Header().Set("X-Content-Type-Options", "nosniff") // no funny business in the browsers :^)

// The TAR has a top-level directory (or file) named by the CID.
if err := tarw.WriteNode(file, rootCid.String()); err != nil {
if err := tarw.WriteFile(file, rootCid.String()); err != nil {
// Update fail metric
i.tarStreamFailMetric.WithLabelValues(rq.contentPath.Namespace()).Observe(time.Since(rq.begin).Seconds())

Expand Down

0 comments on commit 4f392d5

Please sign in to comment.