Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-11-01 10:16:02 +08:00
commit 6d424574c2
8 changed files with 92 additions and 45 deletions

View file

@ -23,6 +23,8 @@ type Sync struct {
Synced int64 `json:"synced"` // 最近同步时间
Stat string `json:"stat"` // 最近同步统计信息
GenerateConflictDoc bool `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档
Provider int `json:"provider"` // 云端存储服务提供者0思源官方1S3 协议对象存储服务
S3 *S3 `json:"s3"` // S3 协议对象存储服务配置
}
func NewSync() *Sync {
@ -31,5 +33,14 @@ func NewSync() *Sync {
Enabled: false,
Mode: 1,
GenerateConflictDoc: false,
Provider: 0,
}
}
type S3 struct {
Endpoint string // 服务端点
AccessKey string // Access Key
SecretKey string // Secret Key
Regin string // 存储区域
Bucket string // 存储空间
}

View file

@ -35,9 +35,8 @@ require (
github.com/olahol/melody v1.1.1
github.com/panjf2000/ants/v2 v2.6.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/qiniu/go-sdk/v7 v7.13.0
github.com/radovskyb/watcher v1.0.7
github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16
github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef
@ -102,6 +101,7 @@ require (
github.com/onsi/ginkgo/v2 v2.4.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/qiniu/go-sdk/v7 v7.13.0 // indirect
github.com/restic/chunker v0.4.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
@ -111,7 +111,7 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f // indirect
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sync v0.1.0 // indirect

View file

@ -105,6 +105,7 @@ github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
@ -214,8 +215,6 @@ github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVE
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c=
github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
@ -285,17 +284,13 @@ github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvw
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8=
github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.22.0 h1:AIg2/OntwkBiCg5Tt1ayyiF1ArFrWFoCSMtMi/wdApk=
github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/panjf2000/ants/v2 v2.5.0 h1:1rWGWSnxCsQBga+nQbA4/iY6VMeNoOIAM0ZWh9u3q2Q=
github.com/panjf2000/ants/v2 v2.5.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE=
github.com/panjf2000/ants/v2 v2.6.0 h1:xOSpw42m+BMiJ2I33we7h6fYzG4DAlpE1xyI7VS2gxU=
github.com/panjf2000/ants/v2 v2.6.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
@ -358,10 +353,12 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/siyuan-note/dejavu v0.0.0-20221023024107-17bf52da95a1 h1:sk6pyVp22MfFXK8C5YOKD5eqWtvcMnkiEh1nyZlw4aU=
github.com/siyuan-note/dejavu v0.0.0-20221023024107-17bf52da95a1/go.mod h1:f+6y7KcTLlk2N2dLl5HeV/YzkyCTEqWNoMiWT0gkMi8=
github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16 h1:05p9tr+rJrKurRQG3NF9i/IPgGdBMPu5tKi1Ux427lY=
github.com/siyuan-note/dejavu v0.0.0-20221031125623-fe9358b6cc16/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785 h1:ZvlTJvaYf7AsME4cR+qMZVxvRff23KRlkqtiHc/W4wI=
github.com/siyuan-note/dejavu v0.0.0-20221031154617-cd9466fb0785/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f h1:pN62Dby/Pt4gejJqNJJxWW72LXBKP1ZF2f1vYh7L5Wg=
github.com/siyuan-note/dejavu v0.0.0-20221031160243-9bedc511961f/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a h1:bE/9NcE4GUl9ooSfry7hp0jJ+9zb3EFQ1YILL3mzchQ=
github.com/siyuan-note/dejavu v0.0.0-20221101010132-53c11123d85a/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=
@ -370,8 +367,6 @@ github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef h1:mbDOxW0N2O
github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef/go.mod h1:NmpSIVtIGy8eNWapjDIiiCw5+5r5wxC76k40oG+WRXQ=
github.com/siyuan-note/httpclient v0.0.0-20221019094331-c904ac9be571 h1:AclwUOWgJQt1F8AXc2s6l/J+Edp/GYIgbI2/RoNlKU0=
github.com/siyuan-note/httpclient v0.0.0-20221019094331-c904ac9be571/go.mod h1:FTPEFG3q0LAn33zON47HeRbLOWNk7HM+OPafmQgq4hU=
github.com/siyuan-note/logging v0.0.0-20220717040626-f796b05ee520 h1:kscYjMt7jXYdd7Qj2OSUoBnoHc5B0U/E6OSx86VRLr4=
github.com/siyuan-note/logging v0.0.0-20220717040626-f796b05ee520/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccYjsadwNBI11he+Wn25hI9lCma4uYoIYEM=
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@ -438,10 +433,10 @@ golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf h1:nFVjjKDgNY37+ZSYCJmtYf7tOlfQswHqplG2eosjOMg=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f h1:Al51T6tzvuh3oiwX11vex3QgJ2XTedFPGmbEVh8cdoc=
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

View file

@ -992,11 +992,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
return
}
if depth := strings.Count(toPath, "/"); 6 < depth && !Conf.FileTree.AllowCreateDeeper {
err = errors.New(Conf.Language(118))
return
}
fromDir := strings.TrimSuffix(fromPath, ".sy")
if strings.HasPrefix(toPath, fromDir) {
err = errors.New(Conf.Language(87))
@ -1016,6 +1011,12 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
return
}
childDepth := util.GetChildDocDepth(filepath.Join(util.DataDir, fromBoxID, fromPath))
if depth := strings.Count(toPath, "/") + childDepth; 6 < depth && !Conf.FileTree.AllowCreateDeeper {
err = errors.New(Conf.Language(118))
return
}
toBox := Conf.Box(toBoxID)
if nil == toBox {
err = errors.New(Conf.Language(0))

View file

@ -34,8 +34,8 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/dejavu/cloud"
"github.com/siyuan-note/dejavu/entity"
"github.com/siyuan-note/dejavu/transport"
"github.com/siyuan-note/encryption"
"github.com/siyuan-note/eventbus"
"github.com/siyuan-note/httpclient"
@ -378,6 +378,7 @@ func TagSnapshot(id, name string) (err error) {
return
}
name = strings.TrimSpace(name)
name = gulu.Str.RemoveInvisible(name)
if "" == name {
err = errors.New(Conf.Language(142))
@ -413,6 +414,7 @@ func IndexRepo(memo string) (err error) {
return
}
memo = strings.TrimSpace(memo)
memo = gulu.Str.RemoveInvisible(memo)
if "" == memo {
err = errors.New(Conf.Language(142))
@ -809,17 +811,17 @@ func resetRepository(repo *dejavu.Repo) (index *entity.Index, err error) {
}
func newRepository() (ret *dejavu.Repo, err error) {
transportConf, err := buildRepoTransportConf()
cloudConf, err := buildCloudConf()
if nil != err {
return
}
// TODO: 数据同步支持接入第三方对象存储服务 https://github.com/siyuan-note/siyuan/issues/6426
siyuanTransport := &transport.SiYuan{Conf: transportConf}
cloudSiYuan := &cloud.SiYuan{BaseCloud: &cloud.BaseCloud{Conf: cloudConf}}
ignoreLines := getIgnoreLines()
ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置
ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, siyuanTransport)
ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines, cloudSiYuan)
if nil != err {
logging.LogErrorf("init data repo failed: %s", err)
}
@ -998,7 +1000,7 @@ func subscribeEvents() {
})
}
func buildRepoTransportConf() (ret *transport.Conf, err error) {
func buildCloudConf() (ret *cloud.Conf, err error) {
if !IsValidCloudDirName(Conf.Sync.CloudName) {
logging.LogWarnf("invalid cloud repo name, rename it to [main]")
Conf.Sync.CloudName = "main"
@ -1011,7 +1013,7 @@ func buildRepoTransportConf() (ret *transport.Conf, err error) {
token = Conf.User.UserToken
}
ret = &transport.Conf{
ret = &cloud.Conf{
Dir: Conf.Sync.CloudName,
UserID: userId,
Token: token,

View file

@ -29,7 +29,7 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/dejavu/cloud"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -378,7 +378,7 @@ func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) {
}
func formatErrorMsg(err error) string {
if errors.Is(err, dejavu.ErrCloudAuthFailed) {
if errors.Is(err, cloud.ErrCloudAuthFailed) {
return Conf.Language(31) + " v" + util.Ver
}

View file

@ -62,12 +62,12 @@ func getNewVerInstallPkgPath() string {
return ""
}
downloadPkgURL, checksum, err := getUpdatePkg()
if nil != err || "" == downloadPkgURL || "" == checksum {
downloadPkgURLs, checksum, err := getUpdatePkg()
if nil != err || 1 > len(downloadPkgURLs) || "" == checksum {
return ""
}
pkg := path.Base(downloadPkgURL)
pkg := path.Base(downloadPkgURLs[0])
ret := filepath.Join(util.TempDir, "install", pkg)
localChecksum, _ := sha256Hash(ret)
if checksum != localChecksum {
@ -92,21 +92,32 @@ func checkDownloadInstallPkg() {
checkDownloadInstallPkgLock.Lock()
defer checkDownloadInstallPkgLock.Unlock()
downloadPkgURL, checksum, err := getUpdatePkg()
if nil != err || "" == downloadPkgURL || "" == checksum {
downloadPkgURLs, checksum, err := getUpdatePkg()
if nil != err || 1 > len(downloadPkgURLs) || "" == checksum {
return
}
downloadInstallPkg(downloadPkgURL, checksum)
msgId := util.PushMsg(Conf.Language(103), 60*1000*10)
succ := false
for _, downloadPkgURL := range downloadPkgURLs {
err = downloadInstallPkg(downloadPkgURL, checksum)
if nil == err {
succ = true
break
}
}
if !succ {
util.PushUpdateMsg(msgId, Conf.Language(104), 7000)
}
}
func getUpdatePkg() (downloadPkgURL, checksum string, err error) {
func getUpdatePkg() (downloadPkgURLs []string, checksum string, err error) {
result, err := util.GetRhyResult(false)
if nil != err {
return
}
installPkgSite := result["installPkg"].(string)
ver := result["ver"].(string)
if isVersionUpToDate(ver) {
return
@ -125,13 +136,20 @@ func getUpdatePkg() (downloadPkgURL, checksum string, err error) {
suffix = "linux.AppImage"
}
pkg := "siyuan-" + ver + "-" + suffix
downloadPkgURL = installPkgSite + "siyuan/" + pkg
url := "https://github.com/siyuan-note/siyuan/releases/download/v" + ver + "/" + pkg
downloadPkgURLs = append(downloadPkgURLs, url)
url = "https://ghproxy.com/" + url
downloadPkgURLs = append(downloadPkgURLs, url)
url = "https://release.b3log.org/siyuan/" + pkg
downloadPkgURLs = append(downloadPkgURLs, url)
checksums := result["checksums"].(map[string]interface{})
checksum = checksums[pkg].(string)
return
}
func downloadInstallPkg(pkgURL, checksum string) {
func downloadInstallPkg(pkgURL, checksum string) (err error) {
if "" == pkgURL || "" == checksum {
return
}
@ -145,22 +163,20 @@ func downloadInstallPkg(pkgURL, checksum string) {
}
}
err := os.MkdirAll(filepath.Join(util.TempDir, "install"), 0755)
err = os.MkdirAll(filepath.Join(util.TempDir, "install"), 0755)
if nil != err {
logging.LogErrorf("create temp install dir failed: %s", err)
return
}
logging.LogInfof("downloading install package [%s]", pkgURL)
msgId := util.PushMsg(Conf.Language(103), 60*1000*10)
client := req.C().SetTLSHandshakeTimeout(7 * time.Second).SetTimeout(10 * time.Minute)
callback := func(info req.DownloadInfo) {
//logging.LogDebugf("downloading install package [%s %.2f%%]", pkgURL, float64(info.DownloadedSize)/float64(info.Response.ContentLength)*100.0)
}
_, err = client.R().SetOutputFile(savePath).SetDownloadCallback(callback).Get(pkgURL)
if nil != err {
logging.LogErrorf("download install package failed: %s", err)
util.PushUpdateMsg(msgId, Conf.Language(104), 7000)
logging.LogErrorf("download install package [%s] failed: %s", pkgURL, err)
return
}
@ -170,6 +186,7 @@ func downloadInstallPkg(pkgURL, checksum string) {
return
}
logging.LogInfof("downloaded install package [%s] to [%s]", pkgURL, savePath)
return
}
func sha256Hash(filename string) (ret string, err error) {

View file

@ -21,6 +21,7 @@ import (
"net"
"os"
"path"
"path/filepath"
"strings"
"time"
@ -138,3 +139,23 @@ func TimeFromID(id string) (ret string) {
ret = id[:14]
return
}
func GetChildDocDepth(treeAbsPath string) (ret int) {
dir := strings.TrimSuffix(treeAbsPath, ".sy")
if !gulu.File.IsDir(dir) {
return
}
baseDepth := strings.Count(filepath.ToSlash(treeAbsPath), "/")
depth := 1
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
p := filepath.ToSlash(path)
currentDepth := strings.Count(p, "/")
if depth < currentDepth {
depth = currentDepth
}
return nil
})
ret = depth - baseDepth
return
}