Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix minor mfs truncate bug #2382

Merged
merged 1 commit into from
Feb 23, 2016
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
2 changes: 1 addition & 1 deletion mfs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) {
ndir := NewDirectory(d.ctx, name, nd, d, d.dserv)
d.childDirs[name] = ndir
return ndir, nil
case ufspb.Data_File:
case ufspb.Data_File, ufspb.Data_Raw:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @whyrusleeping, doesn't this fix imply that the truncate option is changing the file type from Data_File to Data_Raw? Is this intended?

nfi, err := NewFile(name, nd, d, d.dserv)
if err != nil {
return nil, err
Expand Down
19 changes: 19 additions & 0 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,25 @@ test_files_api() {
verify_dir_contents /
'

# test truncating
test_expect_success "create a new file" '
echo "some content" | ipfs files write --create /cats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also verify its contents are as expected before doing the truncate below?

'

test_expect_success "truncate and write over that file" '
echo "fish" | ipfs files write --truncate /cats
'

test_expect_success "output looks good" '
ipfs files read /cats > file_out &&
echo "fish" > file_exp &&
test_cmp file_out file_exp
'

test_expect_success "cleanup" '
ipfs files rm /cats
'

# test flush flags
test_expect_success "mkdir --flush works" '
ipfs files mkdir --flush --parents /flushed/deep
Expand Down
2 changes: 1 addition & 1 deletion unixfs/mod/dagmodifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"
"os"

proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"

key "github.com/ipfs/go-ipfs/blocks/key"
Expand Down
14 changes: 14 additions & 0 deletions unixfs/mod/dagmodifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) {
if size != 10 {
t.Fatal("size was incorrect!")
}

err = dagmod.Truncate(0)
if err != nil {
t.Fatal(err)
}

size, err = dagmod.Size()
if err != nil {
t.Fatal(err)
}

if size != 0 {
t.Fatal("size was incorrect!")
}
}

func TestSparseWrite(t *testing.T) {
Expand Down