@cryptotaxi247 / kubo / commits / 3ee3c44d7

flush!

Jeromy committed Oct 21, 2014 at 23:03 UTC 3ee3c44d7c999f8f2a626be669ffb2a96c137ecd
2 files changed +29 -5
core/commands/pin.go
+2 -2
@@ -34,7 +34,7 @@ func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
34 return fmt.Errorf("pin: %v", err)
35 }
36 }
37 - return nil
37 + return n.Pinning.Flush()
38 }
39
40 func Unpin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
@@ -54,5 +54,5 @@ func Unpin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.
54 return fmt.Errorf("pin: %v", err)
55 }
56 }
57 - return nil
57 + return n.Pinning.Flush()
58 }
pin/pin.go
+27 -3
@@ -3,6 +3,8 @@ package pin
3 import (
4
5 //ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
6 + "bytes"
7 + "encoding/json"
8 "sync"
9
10 ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
@@ -175,19 +177,41 @@ func LoadPinner(d ds.Datastore, dserv *mdag.DAGService) (Pinner, error) {
177 func (p *pinner) Flush() error {
178 p.lock.RLock()
179 defer p.lock.RUnlock()
180 + buf := new(bytes.Buffer)
181 + enc := json.NewEncoder(buf)
182 +
183 recurse := p.recursePin.GetKeys()
179 - err := p.dstore.Put(recursePinDatastoreKey, recurse)
184 + err := enc.Encode(recurse)
185 if err != nil {
186 return err
187 }
188
189 + err = p.dstore.Put(recursePinDatastoreKey, buf.Bytes())
190 + if err != nil {
191 + return err
192 + }
193 +
194 + buf = new(bytes.Buffer)
195 + enc = json.NewEncoder(buf)
196 direct := p.directPin.GetKeys()
185 - err = p.dstore.Put(directPinDatastoreKey, direct)
197 + err = enc.Encode(direct)
198 + if err != nil {
199 + return err
200 + }
201 +
202 + err = p.dstore.Put(directPinDatastoreKey, buf.Bytes())
203 + if err != nil {
204 + return err
205 + }
206 +
207 + buf = new(bytes.Buffer)
208 + enc = json.NewEncoder(buf)
209 + err = enc.Encode(p.indirPin.refCounts)
210 if err != nil {
211 return err
212 }
213
190 - err = p.dstore.Put(indirectPinDatastoreKey, p.indirPin.refCounts)
214 + err = p.dstore.Put(indirectPinDatastoreKey, buf.Bytes())
215 if err != nil {
216 return err
217 }