Ver Fonte

фикс создания пустого файла плюс сохранение истории корневых каталогов

kpmy há 8 anos atrás
pai
commit
aff2c0d1fb
2 ficheiros alterados com 16 adições e 4 exclusões
  1. 8 1
      dav_cmd/main.go
  2. 8 3
      wdfs/file.go

+ 8 - 1
dav_cmd/main.go

@@ -4,15 +4,17 @@ import (
 	"log"
 	"net/http"
 	"net/url"
+	"time"
 
 	"fmt"
+	"os"
+
 	"github.com/kpmy/mipfs/ipfs_api"
 	"github.com/kpmy/mipfs/wdfs"
 	"github.com/kpmy/ypk/fn"
 	. "github.com/kpmy/ypk/tc"
 	"github.com/peterbourgon/diskv"
 	"golang.org/x/net/webdav"
-	"os"
 )
 
 var KV *diskv.Diskv
@@ -44,8 +46,13 @@ func main() {
 	rootCh := make(chan string, 16)
 	go func(ch chan string) {
 		for {
+			i := 0
 			for s := range ch {
 				if s != "" {
+					if old, err := KV.Read("root"); err == nil && s != string(old) {
+						KV.Write(fmt.Sprint("root.", time.Now().UnixNano(), ".", i), old)
+						i++
+					}
 					KV.Write("root", []byte(s))
 				} else {
 					Halt(100, "empty root")

+ 8 - 3
wdfs/file.go

@@ -64,8 +64,7 @@ func (f *file) Close() error {
 		close(f.wr)
 		f.wg.Wait()
 	} else if !f.ch.exists() {
-		log.Println("empty file close")
-		return os.ErrNotExist
+		f.update(nil)
 	}
 	return nil
 }
@@ -133,8 +132,14 @@ func (f *file) Stat() (os.FileInfo, error) {
 	return f, nil
 }
 
+const emptyFileHash = "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"
+
 func (f *file) update(data io.ReadCloser) {
-	f.ch.Hash, _ = ipfs_api.Shell().Add(data)
+	if !fn.IsNil(data) {
+		f.ch.Hash, _ = ipfs_api.Shell().Add(data)
+	} else {
+		f.ch.Hash = emptyFileHash
+	}
 	for tail := f.ch.up; tail != nil; tail = tail.up {
 		tail.Hash, _ = ipfs_api.Shell().PatchLink(tail.Hash, tail.down.name, tail.down.Hash, false)
 		if tail.down.Hash == f.ch.Hash {