local sink: write and update files
fix issues with https://github.com/chrislusf/seaweedfs/issues/2084
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/chrislusf/seaweedfs/weed/replication/sink"
|
"github.com/chrislusf/seaweedfs/weed/replication/sink"
|
||||||
"github.com/chrislusf/seaweedfs/weed/replication/source"
|
"github.com/chrislusf/seaweedfs/weed/replication/source"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -86,8 +85,18 @@ func (localsink *LocalSink) CreateEntry(key string, entry *filer_pb.Entry, signa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if entry.IsDirectory {
|
||||||
|
return os.Mkdir(key, os.FileMode(entry.Attributes.FileMode))
|
||||||
|
}
|
||||||
|
|
||||||
|
dstFile, err := os.OpenFile(key, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(entry.Attributes.FileMode))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dstFile.Close()
|
||||||
|
|
||||||
writeFunc := func(data []byte) error {
|
writeFunc := func(data []byte) error {
|
||||||
writeErr := ioutil.WriteFile(key, data, 0755)
|
_, writeErr := dstFile.Write(data)
|
||||||
return writeErr
|
return writeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,5 +113,7 @@ func (localsink *LocalSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, ne
|
|||||||
}
|
}
|
||||||
glog.V(4).Infof("Update Entry key: %s", key)
|
glog.V(4).Infof("Update Entry key: %s", key)
|
||||||
// do delete and create
|
// do delete and create
|
||||||
return false, nil
|
foundExistingEntry = util.FileExists(key)
|
||||||
|
err = localsink.CreateEntry(key, newEntry, signatures)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user