Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
7b0326e2a2
17 changed files with 104 additions and 91 deletions
|
@ -85,7 +85,7 @@ func setFileAnnotation(c *gin.Context) {
|
|||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
if err := gulu.File.WriteFileSafer(writePath, []byte(data), 0644); nil != err {
|
||||
if err := util.WriteFileSafer(writePath, []byte(data)); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
|
@ -106,7 +106,7 @@ func extensionCopy(c *gin.Context) {
|
|||
}
|
||||
fName = fName + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(assets, fName)
|
||||
if err = gulu.File.WriteFileSafer(writePath, data, 0644); nil != err {
|
||||
if err = util.WriteFileSafer(writePath, data); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
break
|
||||
|
|
|
@ -374,7 +374,7 @@ func installPackage(data []byte, installPath string) (err error) {
|
|||
}
|
||||
}
|
||||
srcPath := filepath.Join(unzipPath, dir)
|
||||
if err = gulu.File.Copy(srcPath, installPath); nil != err {
|
||||
if err = util.Copy(srcPath, installPath); nil != err {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
@ -123,6 +123,7 @@ func WriteTree(tree *parse.Tree) (err error) {
|
|||
if err = os.MkdirAll(filepath.Dir(filePath), 0755); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = filelock.LockFileWrite(filePath, output); nil != err {
|
||||
msg := fmt.Sprintf("write data [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf(msg)
|
||||
|
|
|
@ -141,9 +141,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
name = util.FilterFileName(name)
|
||||
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(util.DataDir, "assets", name)
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
if err = gulu.File.WriteFileSafer(writePath, data, 0644); nil != err {
|
||||
if err = util.WriteFileSafer(writePath, data); nil != err {
|
||||
logging.LogErrorf("write downloaded net img [%s] to local assets [%s] failed: %s", u, writePath, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
|
@ -385,7 +383,7 @@ func saveWorkspaceAssets(assets []string) {
|
|||
logging.LogErrorf("create assets conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.File.WriteFileSafer(confPath, data, 0644); nil != err {
|
||||
if err = util.WriteFileSafer(confPath, data); nil != err {
|
||||
logging.LogErrorf("write assets conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
@ -480,7 +478,7 @@ func RenameAsset(oldPath, newName string) (err error) {
|
|||
|
||||
newName = util.AssetName(newName) + filepath.Ext(oldPath)
|
||||
newPath := "assets/" + newName
|
||||
if err = gulu.File.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err {
|
||||
if err = util.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err {
|
||||
logging.LogErrorf("copy asset [%s] failed: %s", oldPath, err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -55,9 +55,6 @@ func InstalledWidgets() (widgets []*bazaar.Widget) {
|
|||
}
|
||||
|
||||
func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.DataDir, "widgets", widgetName)
|
||||
err := bazaar.InstallWidget(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
|
@ -67,9 +64,6 @@ func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
|
|||
}
|
||||
|
||||
func UninstallBazaarWidget(widgetName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.DataDir, "widgets", widgetName)
|
||||
err := bazaar.UninstallWidget(installPath)
|
||||
if nil != err {
|
||||
|
@ -105,9 +99,6 @@ func InstalledIcons() (icons []*bazaar.Icon) {
|
|||
}
|
||||
|
||||
func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.IconsPath, iconName)
|
||||
err := bazaar.InstallIcon(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
|
@ -120,9 +111,6 @@ func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
|
|||
}
|
||||
|
||||
func UninstallBazaarIcon(iconName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.IconsPath, iconName)
|
||||
err := bazaar.UninstallIcon(installPath)
|
||||
if nil != err {
|
||||
|
@ -160,9 +148,6 @@ func InstalledThemes() (ret []*bazaar.Theme) {
|
|||
}
|
||||
|
||||
func InstallBazaarTheme(repoURL, repoHash, themeName string, mode int, update bool) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
closeThemeWatchers()
|
||||
|
||||
installPath := filepath.Join(util.ThemesPath, themeName)
|
||||
|
@ -188,9 +173,6 @@ func InstallBazaarTheme(repoURL, repoHash, themeName string, mode int, update bo
|
|||
}
|
||||
|
||||
func UninstallBazaarTheme(themeName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
closeThemeWatchers()
|
||||
|
||||
installPath := filepath.Join(util.ThemesPath, themeName)
|
||||
|
@ -224,9 +206,6 @@ func InstalledTemplates() (templates []*bazaar.Template) {
|
|||
}
|
||||
|
||||
func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.DataDir, "templates", templateName)
|
||||
err := bazaar.InstallTemplate(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
|
@ -236,9 +215,6 @@ func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
|
|||
}
|
||||
|
||||
func UninstallBazaarTemplate(templateName string) error {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
installPath := filepath.Join(util.DataDir, "templates", templateName)
|
||||
err := bazaar.UninstallTemplate(installPath)
|
||||
if nil != err {
|
||||
|
|
|
@ -202,7 +202,7 @@ func (box *Box) saveConf0(data []byte) {
|
|||
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, ".siyuan"), 0755); nil != err {
|
||||
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
if err := filelock.NoLockFileWrite(confPath, data); nil != err {
|
||||
if err := util.WriteFileSafer(confPath, data); nil != err {
|
||||
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +291,9 @@ func (box *Box) Move(oldPath, newPath string) error {
|
|||
fromPath := filepath.Join(boxLocalPath, oldPath)
|
||||
toPath := filepath.Join(boxLocalPath, newPath)
|
||||
filelock.ReleaseFileLocks(fromPath)
|
||||
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
if err := os.Rename(fromPath, toPath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(5), box.Name, fromPath, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, box.Name, err)
|
||||
|
@ -310,8 +313,7 @@ func (box *Box) Move(oldPath, newPath string) error {
|
|||
func (box *Box) Remove(path string) error {
|
||||
boxLocalPath := filepath.Join(util.DataDir, box.ID)
|
||||
filePath := filepath.Join(boxLocalPath, path)
|
||||
filelock.ReleaseFileLocks(filePath)
|
||||
if err := os.RemoveAll(filePath); nil != err {
|
||||
if err := util.RemoveAll(filePath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(7), box.Name, path, err)
|
||||
logging.LogErrorf("remove [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
|
|
|
@ -125,8 +125,6 @@ func ExportDataInFolder(exportFolder string) (err error) {
|
|||
defer util.ClearPushProgress(100)
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
exportFolder = filepath.Join(exportFolder, util.CurrentTimeSecondsStr())
|
||||
err = exportData(exportFolder)
|
||||
|
@ -141,8 +139,6 @@ func ExportData() (zipPath string) {
|
|||
defer util.ClearPushProgress(100)
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
||||
|
@ -162,6 +158,9 @@ func exportData(exportFolder string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
err = filelock.ReleaseAllFileLocks()
|
||||
if nil != err {
|
||||
return
|
||||
|
|
|
@ -918,12 +918,9 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
|
|||
}
|
||||
|
||||
func writeJSONQueue(tree *parse.Tree) (err error) {
|
||||
writingDataLock.Lock()
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
writingDataLock.Unlock()
|
||||
return
|
||||
}
|
||||
writingDataLock.Unlock()
|
||||
sql.UpsertTreeQueue(tree)
|
||||
return
|
||||
}
|
||||
|
@ -934,12 +931,9 @@ func indexWriteJSONQueue(tree *parse.Tree) (err error) {
|
|||
}
|
||||
|
||||
func renameWriteJSONQueue(tree *parse.Tree, oldHPath string) (err error) {
|
||||
writingDataLock.Lock()
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
writingDataLock.Unlock()
|
||||
return
|
||||
}
|
||||
writingDataLock.Unlock()
|
||||
sql.RenameTreeQueue(tree, oldHPath)
|
||||
treenode.ReindexBlockTree(tree)
|
||||
return
|
||||
|
@ -1071,9 +1065,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
|
|||
}
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
tree, err := LoadTree(fromBoxID, fromPath)
|
||||
if nil != err {
|
||||
err = ErrBlockNotFound
|
||||
|
@ -1199,9 +1190,6 @@ func RemoveDoc(boxID, p string) (err error) {
|
|||
}
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
tree, err := LoadTree(boxID, p)
|
||||
if nil != err {
|
||||
return
|
||||
|
@ -1215,8 +1203,7 @@ func RemoveDoc(boxID, p string) (err error) {
|
|||
|
||||
historyPath := filepath.Join(historyDir, boxID, p)
|
||||
absPath := filepath.Join(util.DataDir, boxID, p)
|
||||
filelock.ReleaseFileLocks(absPath)
|
||||
if err = gulu.File.Copy(absPath, historyPath); nil != err {
|
||||
if err = util.Copy(absPath, historyPath); nil != err {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(70), box.Name, absPath, err))
|
||||
}
|
||||
|
||||
|
@ -1547,8 +1534,8 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
}
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
box := Conf.Box(boxID)
|
||||
sortIDs := map[string]int{}
|
||||
|
|
|
@ -238,7 +238,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
}
|
||||
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
util.LockWriteFile()
|
||||
|
||||
srcPath := historyPath
|
||||
var destPath string
|
||||
|
@ -249,22 +249,22 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
workingDoc := treenode.GetBlockTree(id)
|
||||
if nil != workingDoc {
|
||||
if err = os.RemoveAll(filepath.Join(util.DataDir, boxID, workingDoc.Path)); nil != err {
|
||||
writingDataLock.Unlock()
|
||||
util.UnlockWriteFile()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
destPath, err = getRollbackDockPath(boxID, historyPath)
|
||||
if nil != err {
|
||||
writingDataLock.Unlock()
|
||||
util.UnlockWriteFile()
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.File.Copy(srcPath, destPath); nil != err {
|
||||
writingDataLock.Unlock()
|
||||
util.UnlockWriteFile()
|
||||
return
|
||||
}
|
||||
writingDataLock.Unlock()
|
||||
util.UnlockWriteFile()
|
||||
|
||||
FullReindex()
|
||||
IncSync()
|
||||
|
|
|
@ -259,7 +259,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
for _, assets := range assetsDirs {
|
||||
if gulu.File.IsDir(assets) {
|
||||
dataAssets := filepath.Join(util.DataDir, "assets")
|
||||
if err = gulu.File.Copy(assets, dataAssets); nil != err {
|
||||
if err = util.Copy(assets, dataAssets); nil != err {
|
||||
logging.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
return
|
||||
}
|
||||
|
@ -267,8 +267,8 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
os.RemoveAll(assets)
|
||||
}
|
||||
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
filelock.ReleaseAllFileLocks()
|
||||
|
||||
|
@ -331,8 +331,8 @@ func ImportData(zipPath string) (err error) {
|
|||
return errors.New("invalid data.zip")
|
||||
}
|
||||
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
filelock.ReleaseAllFileLocks()
|
||||
tmpDataPath := filepath.Join(unzipPath, dirs[0].Name())
|
||||
|
@ -501,8 +501,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
})
|
||||
|
||||
reassignIDUpdated(tree)
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
return io.EOF
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import (
|
|||
|
||||
func CreateBox(name string) (id string, err error) {
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
id = ast.NewNodeID()
|
||||
boxLocalPath := filepath.Join(util.DataDir, id)
|
||||
|
@ -55,8 +53,8 @@ func CreateBox(name string) (id string, err error) {
|
|||
|
||||
func RenameBox(boxID, name string) (err error) {
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
box := Conf.Box(boxID)
|
||||
if nil == box {
|
||||
|
@ -73,8 +71,6 @@ func RenameBox(boxID, name string) (err error) {
|
|||
|
||||
func RemoveBox(boxID string) (err error) {
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
if util.IsReservedFilename(boxID) {
|
||||
return errors.New(fmt.Sprintf("can not remove [%s] caused by it is a reserved file", boxID))
|
||||
|
@ -116,8 +112,6 @@ func RemoveBox(boxID string) (err error) {
|
|||
|
||||
func Unmount(boxID string) {
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
unmount0(boxID)
|
||||
evt := util.NewCmdResult("unmount", 0, util.PushModeBroadcast, 0)
|
||||
|
@ -142,8 +136,6 @@ func unmount0(boxID string) {
|
|||
|
||||
func Mount(boxID string) (alreadyMount bool, err error) {
|
||||
WaitForWritingFiles()
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
localPath := filepath.Join(util.DataDir, boxID)
|
||||
|
||||
|
|
|
@ -221,8 +221,8 @@ func CheckoutRepo(id string) (err error) {
|
|||
}
|
||||
|
||||
util.PushEndlessProgress(Conf.Language(63))
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
WaitForWritingFiles()
|
||||
sql.WaitForWritingDatabase()
|
||||
filelock.ReleaseAllFileLocks()
|
||||
|
|
|
@ -63,8 +63,8 @@ func SyncData(boot, exit, byHand bool) {
|
|||
return
|
||||
}
|
||||
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
util.LockWriteFile()
|
||||
defer util.UnlockWriteFile()
|
||||
|
||||
if util.IsMutexLocked(&syncLock) {
|
||||
logging.LogWarnf("sync is in progress")
|
||||
|
|
|
@ -40,8 +40,6 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
var writingDataLock = sync.Mutex{}
|
||||
|
||||
func IsFoldHeading(transactions *[]*Transaction) bool {
|
||||
if 1 == len(*transactions) && 1 == len((*transactions)[0].DoOperations) {
|
||||
if op := (*transactions)[0].DoOperations[0]; "foldHeading" == op.Action {
|
||||
|
|
|
@ -34,9 +34,6 @@ import (
|
|||
)
|
||||
|
||||
func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]interface{}, err error) {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
succMap = map[string]interface{}{}
|
||||
|
||||
bt := treenode.GetBlockTree(id)
|
||||
|
@ -88,7 +85,7 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter
|
|||
f.Close()
|
||||
return
|
||||
}
|
||||
if err = gulu.File.WriteFileSaferByReader(writePath, f, 0644); nil != err {
|
||||
if err = util.WriteFileSaferByReader(writePath, f); nil != err {
|
||||
f.Close()
|
||||
return
|
||||
}
|
||||
|
@ -104,9 +101,6 @@ func Upload(c *gin.Context) {
|
|||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(200, ret)
|
||||
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if nil != err {
|
||||
logging.LogErrorf("insert asset failed: %s", err)
|
||||
|
@ -174,7 +168,7 @@ func Upload(c *gin.Context) {
|
|||
f.Close()
|
||||
break
|
||||
}
|
||||
if err = gulu.File.WriteFileSaferByReader(writePath, f, 0644); nil != err {
|
||||
if err = util.WriteFileSaferByReader(writePath, f); nil != err {
|
||||
errFiles = append(errFiles, fName)
|
||||
ret.Msg = err.Error()
|
||||
f.Close()
|
||||
|
|
|
@ -17,17 +17,85 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
var writingFileLock = sync.Mutex{}
|
||||
|
||||
func LockWriteFile() {
|
||||
if IsMutexLocked(&writingFileLock) {
|
||||
logging.LogWarnf("write file is locked")
|
||||
return
|
||||
}
|
||||
|
||||
writingFileLock.Lock()
|
||||
}
|
||||
|
||||
func UnlockWriteFile() {
|
||||
if !IsMutexLocked(&writingFileLock) {
|
||||
logging.LogWarnf("write file is not locked")
|
||||
return
|
||||
}
|
||||
writingFileLock.Unlock()
|
||||
}
|
||||
|
||||
func WriteFileSaferByReader(writePath string, reader io.Reader) (err error) {
|
||||
writingFileLock.Lock()
|
||||
defer writingFileLock.Unlock()
|
||||
|
||||
if err = gulu.File.WriteFileSaferByReader(writePath, reader, 0644); nil != err {
|
||||
logging.LogErrorf("write file [%s] failed: %s", writePath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WriteFileSafer(writePath string, data []byte) (err error) {
|
||||
writingFileLock.Lock()
|
||||
defer writingFileLock.Unlock()
|
||||
|
||||
if err = gulu.File.WriteFileSafer(writePath, data, 0644); nil != err {
|
||||
logging.LogErrorf("write file [%s] failed: %s", writePath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Copy(source, dest string) (err error) {
|
||||
writingFileLock.Lock()
|
||||
defer writingFileLock.Unlock()
|
||||
|
||||
filelock.ReleaseFileLocks(source)
|
||||
if err = gulu.File.Copy(source, dest); nil != err {
|
||||
logging.LogErrorf("copy [%s] to [%s] failed: %s", source, dest, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveAll(p string) (err error) {
|
||||
writingFileLock.Lock()
|
||||
defer writingFileLock.Unlock()
|
||||
|
||||
filelock.ReleaseFileLocks(p)
|
||||
if err = os.RemoveAll(p); nil != err {
|
||||
logging.LogErrorf("remove all [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func IsEmptyDir(p string) bool {
|
||||
if !gulu.File.IsDir(p) {
|
||||
return false
|
||||
|
|
Loading…
Add table
Reference in a new issue