From 64bb51b2aba026731017fbb8fb62eaf79bce8ac3 Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Fri, 16 Jul 2021 16:45:26 +0100 Subject: [PATCH] Replace a file if exists on `index.Save` If appendage is needed there is already `car.AttachIndex`. --- v2/index/index.go | 4 ++-- v2/testdata/sample-index.carindex | Bin 209505 -> 41901 bytes 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/v2/index/index.go b/v2/index/index.go index 96b730f..669728b 100644 --- a/v2/index/index.go +++ b/v2/index/index.go @@ -52,9 +52,9 @@ func New(codec multicodec.Code) (Index, error) { } } -// Save writes a generated index into the given `path`. +// Save writes a generated index into the given `path` replacing the file if it exists. func Save(idx Index, path string) error { - stream, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640) + stream, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o640) if err != nil { return err } diff --git a/v2/testdata/sample-index.carindex b/v2/testdata/sample-index.carindex index 0f91e36507fc21d3a93a00f32bf330e024405af8..5df07d379e444d8fa3a0f5b96a59874f208bd0c1 100644 GIT binary patch delta 9 RcmaF(glFw>rVVQs0{|Or1xNq@ delta 21 ScmZ2`oax~co(*dkBO?Hf?+r)* -- GitLab