diff --git a/README.md b/README.md index 4287712a1..5b3c0a802 100644 --- a/README.md +++ b/README.md @@ -282,12 +282,12 @@ SiYuan is made possible by the following open source projects. * [https://github.com/imroc/req](https://github.com/imroc/req) `MIT License` * [https://github.com/jinzhu/copier](https://github.com/jinzhu/copier) `MIT License` * [https://github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) `MIT License` -* [https://github.com/mattn/go-zglob](https://github.com/mattn/go-zglob) `MIT License` * [https://github.com/mitchellh/go-ps](https://github.com/mitchellh/go-ps) `MIT License` * [https://github.com/mssola/user_agent](https://github.com/mssola/user_agent) `MIT License` * [https://github.com/panjf2000/ants](https://github.com/panjf2000/ants) `MIT License` * [https://github.com/patrickmn/go-cache](https://github.com/patrickmn/go-cache) `MIT License` * [https://github.com/radovskyb/watcher](https://github.com/radovskyb/watcher) `BSD-3-Clause License` +* [https://github.com/sabhiram/go-gitignore](https://github.com/sabhiram/go-gitignore) `MIT License` * [https://github.com/siyuan-note/dejavu](https://github.com/siyuan-note/dejavu) `Mulan PSL v2` * [https://github.com/siyuan-note/encryption](https://github.com/siyuan-note/encryption) `Mulan PSL v2` * [https://github.com/siyuan-note/filelock](https://github.com/siyuan-note/filelock) `Mulan PSL v2` diff --git a/README_zh_CN.md b/README_zh_CN.md index ab9388429..d6ae72435 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -291,12 +291,12 @@ * [https://github.com/imroc/req](https://github.com/imroc/req) `MIT License` * [https://github.com/jinzhu/copier](https://github.com/jinzhu/copier) `MIT License` * [https://github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) `MIT License` -* [https://github.com/mattn/go-zglob](https://github.com/mattn/go-zglob) `MIT License` * [https://github.com/mitchellh/go-ps](https://github.com/mitchellh/go-ps) `MIT License` * [https://github.com/mssola/user_agent](https://github.com/mssola/user_agent) `MIT License` * [https://github.com/panjf2000/ants](https://github.com/panjf2000/ants) `MIT License` * [https://github.com/patrickmn/go-cache](https://github.com/patrickmn/go-cache) `MIT License` * [https://github.com/radovskyb/watcher](https://github.com/radovskyb/watcher) `BSD-3-Clause License` +* [https://github.com/sabhiram/go-gitignore](https://github.com/sabhiram/go-gitignore) `MIT License` * [https://github.com/siyuan-note/dejavu](https://github.com/siyuan-note/dejavu) `Mulan PSL v2` * [https://github.com/siyuan-note/encryption](https://github.com/siyuan-note/encryption) `Mulan PSL v2` * [https://github.com/siyuan-note/filelock](https://github.com/siyuan-note/filelock) `Mulan PSL v2` diff --git a/app/guide/20210808180117-6v0mkxr/.siyuan/sort.json b/app/guide/20210808180117-6v0mkxr/.siyuan/sort.json index ee00a9d15..189ae6f0b 100644 --- a/app/guide/20210808180117-6v0mkxr/.siyuan/sort.json +++ b/app/guide/20210808180117-6v0mkxr/.siyuan/sort.json @@ -1,6 +1,6 @@ { "20200923234011-ieuun1p": 1, - "20200923234602-gy54e67": 5, + "20200923234602-gy54e67": 4, "20200923234731-h3zkwm2": 2, "20200924095938-a9p5450": 2, "20200924100110-vcg96wy": 1, @@ -16,7 +16,7 @@ "20200924101256-f8b1sbi": 3, "20201004194026-s8h2cog": 15, "20201117112518-dott91x": 6, - "20201121224345-rc27qvo": 4, + "20201121224345-rc27qvo": 5, "20201204184532-3qm9l8n": 8, "20201210233038-3xr19g5": 5, "20201222100222-q47d64s": 2, diff --git a/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy b/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy index ef581f105..a55d127fb 100644 --- a/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy +++ b/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy @@ -6,7 +6,7 @@ "id": "20201121224345-rc27qvo", "title": "Acknowledgements", "type": "doc", - "updated": "20220623012804" + "updated": "20220627111416" }, "Children": [ { @@ -29,7 +29,7 @@ "ListData": {}, "Properties": { "id": "20220522101213-z3hokh2", - "updated": "20220623012804" + "updated": "20220627111416" }, "Children": [ { @@ -2132,76 +2132,6 @@ } ] }, - { - "ID": "20220522101213-yyqqx6t", - "Type": "NodeListItem", - "ListData": { - "BulletChar": 42, - "Marker": "Kg==" - }, - "Properties": { - "id": "20220522101213-yyqqx6t", - "updated": "20220522101213" - }, - "Children": [ - { - "ID": "20220522101213-1v7s6i8", - "Type": "NodeParagraph", - "Properties": { - "id": "20220522101213-1v7s6i8", - "updated": "20220522101213" - }, - "Children": [ - { - "Type": "NodeLink", - "Data": "span", - "Children": [ - { - "Type": "NodeOpenBracket" - }, - { - "Type": "NodeLinkText", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseBracket" - }, - { - "Type": "NodeOpenParen" - }, - { - "Type": "NodeLinkDest", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseParen" - } - ] - }, - { - "Type": "NodeText", - "Data": " " - }, - { - "Type": "NodeCodeSpan", - "Data": "code", - "Children": [ - { - "Type": "NodeCodeSpanOpenMarker" - }, - { - "Type": "NodeCodeSpanContent", - "Data": "MIT License" - }, - { - "Type": "NodeCodeSpanCloseMarker" - } - ] - } - ] - } - ] - }, { "ID": "20220522101213-s0qn0r1", "Type": "NodeListItem", @@ -2552,6 +2482,76 @@ } ] }, + { + "ID": "20220627111415-46q353e", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220627111415-46q353e", + "updated": "20220627111416" + }, + "Children": [ + { + "ID": "20220627111415-5kxfvm8", + "Type": "NodeParagraph", + "Properties": { + "id": "20220627111415-5kxfvm8", + "updated": "20220627111416" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220615154952-7rst1oe", "Type": "NodeListItem", diff --git a/app/guide/20210808180117-czj9bvb/.siyuan/sort.json b/app/guide/20210808180117-czj9bvb/.siyuan/sort.json index 1eea98291..659382cb3 100644 --- a/app/guide/20210808180117-czj9bvb/.siyuan/sort.json +++ b/app/guide/20210808180117-czj9bvb/.siyuan/sort.json @@ -6,7 +6,7 @@ "20200813093015-u6bopdt": 2, "20200813125307-pxsjela": 1, "20200813131152-0wk5akh": 4, - "20200813163359-v04n73b": 5, + "20200813163359-v04n73b": 4, "20200822191536-rm6hwid": 3, "20200828105441-r76vmu5": 17, "20200905090211-2vixtlf": 2, @@ -16,7 +16,7 @@ "20201002090451-hb9j8ai": 4, "20201004184819-nj8ibyg": 15, "20201117101902-2ewjjum": 6, - "20201121212605-9td1a62": 4, + "20201121212605-9td1a62": 5, "20201204181006-7bkppue": 8, "20201210103036-1x3vm8t": 5, "20201222093044-rx4zjoy": 1, diff --git a/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy b/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy index 94ca11e90..15155e3fe 100644 --- a/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy +++ b/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy @@ -6,7 +6,7 @@ "id": "20201121212605-9td1a62", "title": "致谢", "type": "doc", - "updated": "20220623012801" + "updated": "20220627111458" }, "Children": [ { @@ -29,7 +29,7 @@ "ListData": {}, "Properties": { "id": "20220522101224-ctmcj3d", - "updated": "20220623012801" + "updated": "20220627111458" }, "Children": [ { @@ -2132,76 +2132,6 @@ } ] }, - { - "ID": "20220522101224-q20v5k9", - "Type": "NodeListItem", - "ListData": { - "BulletChar": 42, - "Marker": "Kg==" - }, - "Properties": { - "id": "20220522101224-q20v5k9", - "updated": "20220522101224" - }, - "Children": [ - { - "ID": "20220522101224-9rb8tjn", - "Type": "NodeParagraph", - "Properties": { - "id": "20220522101224-9rb8tjn", - "updated": "20220522101224" - }, - "Children": [ - { - "Type": "NodeLink", - "Data": "span", - "Children": [ - { - "Type": "NodeOpenBracket" - }, - { - "Type": "NodeLinkText", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseBracket" - }, - { - "Type": "NodeOpenParen" - }, - { - "Type": "NodeLinkDest", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseParen" - } - ] - }, - { - "Type": "NodeText", - "Data": " " - }, - { - "Type": "NodeCodeSpan", - "Data": "code", - "Children": [ - { - "Type": "NodeCodeSpanOpenMarker" - }, - { - "Type": "NodeCodeSpanContent", - "Data": "MIT License" - }, - { - "Type": "NodeCodeSpanCloseMarker" - } - ] - } - ] - } - ] - }, { "ID": "20220522101224-z9gf2ew", "Type": "NodeListItem", @@ -2552,6 +2482,76 @@ } ] }, + { + "ID": "20220627111458-122kj45", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220627111458-122kj45", + "updated": "20220627111458" + }, + "Children": [ + { + "ID": "20220627111458-teblixm", + "Type": "NodeParagraph", + "Properties": { + "id": "20220627111458-teblixm", + "updated": "20220627111458" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220615155002-pupf5ye", "Type": "NodeListItem", diff --git a/app/guide/20211226090932-5lcq56f/.siyuan/sort.json b/app/guide/20211226090932-5lcq56f/.siyuan/sort.json index fa16dff18..fa0be4276 100644 --- a/app/guide/20211226090932-5lcq56f/.siyuan/sort.json +++ b/app/guide/20211226090932-5lcq56f/.siyuan/sort.json @@ -1,4 +1,9 @@ { + "20211226114339-dk0gtpr": 4, + "20211226114929-08ap1r0": 5, + "20211226115043-afhev0g": 3, + "20211226115227-r1rty9v": 2, + "20211226115423-d5z1joq": 1, "20211226115825-mhcslw2": 1, "20211226120055-9mityht": 1, "20211226120147-ib6yy3i": 2, diff --git a/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy b/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy index 1e08a4d71..74c6461d6 100644 --- a/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy +++ b/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy @@ -5,7 +5,7 @@ "icon": "1f64f", "id": "20211226114929-08ap1r0", "title": "致謝", - "updated": "20220623012807" + "updated": "20220627111449" }, "Children": [ { @@ -28,7 +28,7 @@ "ListData": {}, "Properties": { "id": "20220326092650-r61gazd", - "updated": "20220623012807" + "updated": "20220627111449" }, "Children": [ { @@ -2131,76 +2131,6 @@ } ] }, - { - "ID": "20220326092650-9kiqzey", - "Type": "NodeListItem", - "ListData": { - "BulletChar": 42, - "Marker": "Kg==" - }, - "Properties": { - "id": "20220326092650-9kiqzey", - "updated": "20220326092650" - }, - "Children": [ - { - "ID": "20220326092650-rqswxe2", - "Type": "NodeParagraph", - "Properties": { - "id": "20220326092650-rqswxe2", - "updated": "20220326092650" - }, - "Children": [ - { - "Type": "NodeLink", - "Data": "span", - "Children": [ - { - "Type": "NodeOpenBracket" - }, - { - "Type": "NodeLinkText", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseBracket" - }, - { - "Type": "NodeOpenParen" - }, - { - "Type": "NodeLinkDest", - "Data": "https://github.com/mattn/go-zglob" - }, - { - "Type": "NodeCloseParen" - } - ] - }, - { - "Type": "NodeText", - "Data": " " - }, - { - "Type": "NodeCodeSpan", - "Data": "code", - "Children": [ - { - "Type": "NodeCodeSpanOpenMarker" - }, - { - "Type": "NodeCodeSpanContent", - "Data": "MIT License" - }, - { - "Type": "NodeCodeSpanCloseMarker" - } - ] - } - ] - } - ] - }, { "ID": "20220326092650-13vd1m8", "Type": "NodeListItem", @@ -2551,6 +2481,76 @@ } ] }, + { + "ID": "20220627111449-fd85wp4", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220627111449-fd85wp4", + "updated": "20220627111449" + }, + "Children": [ + { + "ID": "20220627111449-lv7og5c", + "Type": "NodeParagraph", + "Properties": { + "id": "20220627111449-lv7og5c", + "updated": "20220627111449" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/sabhiram/go-gitignore" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220615154944-8ye5ub9", "Type": "NodeListItem", diff --git a/kernel/go.mod b/kernel/go.mod index ecf870841..a1ddea600 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -33,13 +33,13 @@ require ( github.com/imroc/req/v3 v3.13.1 github.com/jinzhu/copier v0.3.5 github.com/mattn/go-sqlite3 v2.0.3+incompatible - github.com/mattn/go-zglob v0.0.3 github.com/mitchellh/go-ps v1.0.0 github.com/mssola/user_agent v0.5.3 github.com/panjf2000/ants/v2 v2.5.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/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/siyuan-note/dejavu v0.0.0-20220626025117-e5db5c782cbb github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f diff --git a/kernel/go.sum b/kernel/go.sum index 6b133fd66..cdef90d50 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -345,8 +345,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To= -github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= @@ -409,6 +407,8 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= +github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -421,8 +421,6 @@ github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/siyuan-note/dejavu v0.0.0-20220626024131-25831e573009 h1:w2GvjKF1xFn+Swo+e+eOL9l/KQ8FvtJbwshsBInuPKg= -github.com/siyuan-note/dejavu v0.0.0-20220626024131-25831e573009/go.mod h1:i7dnOgHM41EA7xIX2CYSxYe0WhksGZidQQsLvWryK7w= github.com/siyuan-note/dejavu v0.0.0-20220626025117-e5db5c782cbb h1:7HmFGziI6a8JctJ9ouuZ4fHSsFH1GXhGfoN5pxIc2Ds= github.com/siyuan-note/dejavu v0.0.0-20220626025117-e5db5c782cbb/go.mod h1:i7dnOgHM41EA7xIX2CYSxYe0WhksGZidQQsLvWryK7w= github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI= diff --git a/kernel/model/file.go b/kernel/model/file.go index cfacabc7e..c9fe820ab 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -657,7 +657,7 @@ func GetDoc(id string, index int, keyword string, mode int, size int) (blockCoun } func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeading bool) (nodes []*ast.Node, eof bool) { - if 2 == mode { // 向下 + if 0 == mode /* 仅当前 */ || 2 == mode /* 向下 */ { next := node.Next if ast.NodeHeading == node.Type && "1" == node.IALAttr("fold") { // 标题展开时进行动态加载导致重复内容 https://github.com/siyuan-note/siyuan/issues/4671 diff --git a/kernel/model/import.go b/kernel/model/import.go index e08dc59a4..f5aabfae6 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -38,7 +38,6 @@ import ( "github.com/88250/lute/html" "github.com/88250/lute/parse" "github.com/88250/protyle" - "github.com/mattn/go-zglob" "github.com/siyuan-note/filelock" "github.com/siyuan-note/siyuan/kernel/filesys" "github.com/siyuan-note/siyuan/kernel/sql" @@ -234,21 +233,22 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { } } - assetsDirs, err := zglob.Glob(unzipRootPath + "/**/assets") - if nil != err { - return - } - if 0 < len(assetsDirs) { - for _, assets := range assetsDirs { - if gulu.File.IsDir(assets) { - dataAssets := filepath.Join(util.DataDir, "assets") - if err = gulu.File.Copy(assets, dataAssets); nil != err { - util.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err) - return - } - } - os.RemoveAll(assets) + var assetsDirs []string + filepath.Walk(unzipRootPath, func(path string, info fs.FileInfo, err error) error { + if strings.Contains(path, "assets") && info.IsDir() { + assetsDirs = append(assetsDirs, path) } + return nil + }) + for _, assets := range assetsDirs { + if gulu.File.IsDir(assets) { + dataAssets := filepath.Join(util.DataDir, "assets") + if err = gulu.File.Copy(assets, dataAssets); nil != err { + util.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err) + return + } + } + os.RemoveAll(assets) } writingDataLock.Lock() diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 7838aeb9b..e54b24fb8 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -34,8 +34,7 @@ import ( "github.com/88250/gulu" "github.com/dustin/go-humanize" - "github.com/emirpasic/gods/sets/hashset" - "github.com/mattn/go-zglob" + gitignore "github.com/sabhiram/go-gitignore" "github.com/siyuan-note/encryption" "github.com/siyuan-note/filelock" "github.com/siyuan-note/siyuan/kernel/cache" @@ -1253,9 +1252,8 @@ func IsValidCloudDirName(cloudDirName string) bool { func getSyncExcludedList(localDirPath string) (ret map[string]bool) { syncIgnoreList := getSyncIgnoreList() ret = map[string]bool{} - ignores := syncIgnoreList.Values() - for _, p := range ignores { - relPath := p.(string) + for _, p := range syncIgnoreList { + relPath := p relPath = pathSha256Short(relPath, "/") relPath = filepath.Join(localDirPath, relPath) ret[relPath] = true @@ -1263,8 +1261,7 @@ func getSyncExcludedList(localDirPath string) (ret map[string]bool) { return } -func getSyncIgnoreList() (ret *hashset.Set) { - ret = hashset.New() +func getSyncIgnoreList() (ret []string) { ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore") os.MkdirAll(filepath.Dir(ignore), 0755) if !gulu.File.IsExist(ignore) { @@ -1287,37 +1284,16 @@ func getSyncIgnoreList() (ret *hashset.Set) { lines = append(lines, "20210808180117-czj9bvb/**/*") lines = append(lines, "20211226090932-5lcq56f/**/*") - var parents []string - for _, line := range lines { - if idx := strings.Index(line, "/*"); -1 < idx { - parent := line[:idx] - parents = append(parents, parent) + lines = gulu.Str.RemoveDuplicatedElem(lines) + gi := gitignore.CompileIgnoreLines(lines...) + filepath.Walk(util.DataDir, func(p string, info os.FileInfo, err error) error { + p = strings.TrimPrefix(p, util.DataDir+string(os.PathSeparator)) + p = filepath.ToSlash(p) + if gi.MatchesPath(p) { + ret = append(ret, p) } - } - lines = append(lines, parents...) - - for _, line := range lines { - line = strings.TrimSpace(line) - if "" == line { - continue - } - pattern := filepath.Join(util.DataDir, line) - pattern = filepath.FromSlash(pattern) - matches, globErr := zglob.Glob(pattern) - if nil != globErr && globErr != os.ErrNotExist { - util.LogErrorf("glob [%s] failed: %s", line, globErr) - continue - } - for _, m := range matches { - m = filepath.ToSlash(m) - if strings.Contains(m, ".siyuan/history") { - continue - } - - m = strings.TrimPrefix(m, filepath.ToSlash(util.DataDir+string(os.PathSeparator))) - ret.Add(m) - } - } + return nil + }) return }