bugfix synfile when file delete

This commit is contained in:
s_jqzhang 2019-02-22 16:23:59 +08:00
parent 36a6bdd864
commit fe9a5afe60
2 changed files with 30 additions and 23 deletions

View File

@ -178,6 +178,8 @@ func main() {
# 重要说明
## 在issue中有很多实际使用的问题及回答很多已关闭请查看已关闭的issue
## 项目从v1.1.8开始进入稳定状态
# Q&A
- 在微信讨论群中大家都问到go-fastdfs性能怎样
@ -326,7 +328,7 @@ sts["Fs.ErrorSetSize"] = this.errorset.Cardinality() 这个会导致内存增
```
- 如何编译?
- 如何编译(go1.9.2+)
```
git clone https://github.com/sjqzhang/go-fastdfs.git
cd go-fastdfs
@ -381,13 +383,17 @@ culr -C - http://10.1.5.9:8080/group1/default/20190128/16/10/2G
- Docker如何部署
```
步骤:
一、构建镜像
docker build . -t fastdfs
二、运行容器(使用环境变量 GO_FASTDFS_DIR 指向存储目录。)
docker run --name fastdfs -v ~:/data/fastdfs -e GO_FASTDFS_DIR=/data/fastdfs fastdfs
方式一、
一、构建镜像
docker build . -t fastdfs
二、运行容器(使用环境变量 GO_FASTDFS_DIR 指向存储目录。)
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
方式二、
一、拉取镜像
docker pull sjqzhang/go-fastdfs
二、运行容器
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
```

View File

@ -1114,7 +1114,12 @@ func (this *Server) DownloadFromPeer(peer string, fileInfo *FileInfo) {
data []byte
)
if this.CheckFileExistByMd5(fileInfo.Md5, fileInfo) {
filename = fileInfo.Name
if fileInfo.ReName != "" {
filename = fileInfo.ReName
}
if this.util.FileExists(DOCKER_DIR+fileInfo.Path+"/"+filename) && this.CheckFileExistByMd5(fileInfo.Md5, fileInfo) {
return
}
@ -1122,11 +1127,6 @@ func (this *Server) DownloadFromPeer(peer string, fileInfo *FileInfo) {
os.MkdirAll(DOCKER_DIR+fileInfo.Path, 0775)
}
filename = fileInfo.Name
if fileInfo.ReName != "" {
filename = fileInfo.ReName
}
//fmt.Println("downloadFromPeer",fileInfo)
p := strings.Replace(fileInfo.Path, STORE_DIR_NAME+"/", "", 1)
@ -1343,7 +1343,8 @@ func (this *Server) Download(w http.ResponseWriter, r *http.Request) {
}
if info, err = os.Stat(fullpath); err != nil {
log.Error(err)
notFound = true
goto NotFound // if return can't not repair file
return
}
@ -1365,8 +1366,8 @@ func (this *Server) Download(w http.ResponseWriter, r *http.Request) {
}
}
if info, err = os.Stat(fullpath); err != nil {
NotFound:
if info, err = os.Stat(fullpath); err != nil || info.Size() == 0 {
log.Error(err)
if isSmallFile && notFound {
pathMd5 = this.util.MD5(smallPath)
@ -1379,7 +1380,6 @@ func (this *Server) Download(w http.ResponseWriter, r *http.Request) {
log.Error(err)
continue
}
if fileInfo.Md5 != "" {
if Config().DownloadUseToken && !isPeer {
@ -1388,9 +1388,7 @@ func (this *Server) Download(w http.ResponseWriter, r *http.Request) {
return
}
}
go this.DownloadFromPeer(peer, fileInfo)
http.Redirect(w, r, peer+r.RequestURI, 302)
return
}
@ -2305,10 +2303,10 @@ func (this *Server) RemoveFile(w http.ResponseWriter, r *http.Request) {
}
if fileInfo.Path != "" && this.util.FileExists(fpath) {
if err=this.RemoveKeyFromLevelDB(fileInfo.Md5);err!=nil {
if err = this.RemoveKeyFromLevelDB(fileInfo.Md5); err != nil {
log.Error(err)
}
if err=this.RemoveKeyFromLevelDB(md5path);err!=nil{
if err = this.RemoveKeyFromLevelDB(md5path); err != nil {
log.Error(err)
}
if err = os.Remove(fpath); err != nil {
@ -2668,8 +2666,10 @@ func (this *Server) SaveSmallFile(fileInfo *FileInfo) (error) {
largeDir string
destPath string
reName string
fileExt string
)
filename = fileInfo.Name
fileExt = path.Ext(filename)
if fileInfo.ReName != "" {
filename = fileInfo.ReName
}
@ -2711,7 +2711,8 @@ func (this *Server) SaveSmallFile(fileInfo *FileInfo) (error) {
}
fileInfo.OffSet = fileInfo.OffSet - 1 //minus 1 byte
fileInfo.Size = fileInfo.Size + 1
fileInfo.ReName = fmt.Sprintf("%s,%d,%d", reName, fileInfo.OffSet, fileInfo.Size)
fileInfo.ReName = fmt.Sprintf("%s,%d,%d,%s", reName, fileInfo.OffSet, fileInfo.Size, fileExt)
if _, err = io.Copy(desFile, srcFile); err != nil {
return err
@ -3581,7 +3582,7 @@ func (this *Server) initTus() {
}
if fileLog, err = os.OpenFile(LOG_DIR+"/tusd.log", os.O_CREATE|os.O_RDWR, 0666); err != nil {
log.Error(err)
fmt.Println(err)
panic("initTus")
}