diff --git a/src/modules/content-files/filedb.c b/src/modules/content-files/filedb.c index 5fa04eda21d0..edecd77f43f5 100644 --- a/src/modules/content-files/filedb.c +++ b/src/modules/content-files/filedb.c @@ -87,7 +87,7 @@ int filedb_put (const char *dbpath, *errstr = "key name too long for internal buffer"; return -1; } - if ((fd = open (path, O_WRONLY | O_CREAT, 0666)) < 0) + if ((fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) return -1; if (write_all (fd, data, size) < 0) { ERRNO_SAFE_WRAP (close, fd); diff --git a/t/t0018-content-files.t b/t/t0018-content-files.t index 2c6691afba37..bf8a24bb7384 100755 --- a/t/t0018-content-files.t +++ b/t/t0018-content-files.t @@ -156,6 +156,26 @@ test_expect_success HAVE_JQ 'kvs-checkpoint.get foo still returns rootref baz' ' test_cmp rootref3.exp rootref3.out ' +test_expect_success HAVE_JQ 'kvs-checkpoint.put updates foo rooref with longer rootref' ' + kvs_checkpoint_put foo abcdefghijklmnopqrstuvwxyz +' + +test_expect_success HAVE_JQ 'kvs-checkpoint.get foo returned rootref with longer rootref' ' + echo abcdefghijklmnopqrstuvwxyz >rootref3.exp && + kvs_checkpoint_get foo | jq -r .value | jq -r .rootref >rootref3.out && + test_cmp rootref3.exp rootref3.out +' + +test_expect_success HAVE_JQ 'kvs-checkpoint.put updates foo rooref to shorter rootref' ' + kvs_checkpoint_put foo foobar +' + +test_expect_success HAVE_JQ 'kvs-checkpoint.get foo returned rootref with shorter rootref' ' + echo foobar >rootref4.exp && + kvs_checkpoint_get foo | jq -r .value | jq -r .rootref >rootref4.out && + test_cmp rootref4.exp rootref4.out +' + test_expect_success 'load with invalid blobref fails' ' test_must_fail backing_load notblobref 2>notblobref.err && grep "invalid blobref" notblobref.err