From f6cd44cdb11f83c6c1d196b3c3e441e7f82c7844 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Mon, 14 Oct 2024 16:48:43 +0200 Subject: [PATCH 1/4] WIP: fix: Let electron-builder notarize app --- .github/workflows/macos.yaml | 1 + electron-builder.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 479a58647..888d52a98 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -37,6 +37,7 @@ env: OS_PROJECT_DOMAIN_NAME: "Default" OS_AUTH_URL: "https://auth.cloud.ovh.net/v3" OS_IDENTITY_API_VERSION: "3" + #APPLE_APP_SPECIFIC_PASSWORD: "${{ secrets.APPLE_ID_PASSWORD }}" jobs: cancel: diff --git a/electron-builder.yml b/electron-builder.yml index 17f2dddb5..bae6185ae 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -47,6 +47,7 @@ mac: - target: dmg arch: - x64 + notarize: false # XXX: we do it ourselves in afterSign dmg: contents: - x: 110 From 12ad2b4644aae241eae7df0f04ba90cb9520401c Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Wed, 16 Oct 2024 12:32:58 +0200 Subject: [PATCH 2/4] WIP --- core/local/chokidar/analysis.js | 36 ++-- core/local/chokidar/local_change.js | 250 +++++++++++++-------------- test/unit/local/chokidar/analysis.js | 25 +-- 3 files changed, 151 insertions(+), 160 deletions(-) diff --git a/core/local/chokidar/analysis.js b/core/local/chokidar/analysis.js index a05e05766..d028f01ca 100644 --- a/core/local/chokidar/analysis.js +++ b/core/local/chokidar/analysis.js @@ -100,18 +100,26 @@ class LocalChangeMap { if (change) return callback(change) } - put(c /*: LocalChange */, updated /*: ?boolean */) { - if (updated) { - for (const [k, v] of this.changesByPath) { - if (v == c) { - this.changesByPath.delete(k) - break - } + put(c /*: LocalChange */, toReplace /*: ?LocalChange */) { + if (toReplace) { + this.changesByPath.delete(toReplace.path.normalize()) + this.changesByPath.set(c.path.normalize(), c) + + if (typeof toReplace.ino === 'number') { + this.changesByInode.set(toReplace.ino, c) + } else { + const index = this.changes.indexOf(toReplace) + this.changes.splice(index, 1, c) + } + } else { + this.changesByPath.set(c.path.normalize(), c) + + if (typeof c.ino === 'number') { + this.changesByInode.set(c.ino, c) + } else { + this.changes.push(c) } } - this.changesByPath.set(c.path.normalize(), c) - if (typeof c.ino === 'number') this.changesByInode.set(c.ino, c) - else this.changes.push(c) } flush() /*: LocalChange[] */ { @@ -176,9 +184,9 @@ function analyseEvents( const result = analyseEvent(e, changesFound) if (result == null) continue // No change was found. Skip event. - // A new change was found or updated - const [change, updated] = result - changesFound.put(change, updated) + // A new change was found or one that should be replaced + const [change, toReplace] = result + changesFound.put(change, toReplace) } catch (err) { const sentry = err.name === 'InvalidLocalMoveEvent' log.error('Invalid local move event', { err, path: e.path, sentry }) @@ -196,7 +204,7 @@ function analyseEvents( function analyseEvent( e /*: LocalEvent */, previousChanges /*: LocalChangeMap */ -) /*: ?[LocalChange, boolean] */ { +) /*: ?[LocalChange, ?LocalChange] */ { const sameInodeChange = previousChanges.findByInode(getInode(e)) switch (e.type) { diff --git a/core/local/chokidar/local_change.js b/core/local/chokidar/local_change.js index 3b9e3d0d3..6dc3d62e6 100644 --- a/core/local/chokidar/local_change.js +++ b/core/local/chokidar/local_change.js @@ -310,7 +310,7 @@ function dirAddition(e /*: LocalDirAdded */) { wip: change.wip }) - return [change, false] + return [change, undefined] } function dirDeletion(e /*: LocalDirUnlinked */) { @@ -325,7 +325,7 @@ function dirDeletion(e /*: LocalDirUnlinked */) { log.debug('unlinkDir = DirDeletion', { path: change.path, ino: change.ino }) - return [change, false] + return [change, undefined] } function fileAddition(e /*: LocalFileAdded */) { @@ -346,7 +346,7 @@ function fileAddition(e /*: LocalFileAdded */) { wip: change.wip }) - return [change, false] + return [change, undefined] } function fileDeletion(e /*: LocalFileUnlinked */) { @@ -361,7 +361,7 @@ function fileDeletion(e /*: LocalFileUnlinked */) { log.debug('unlink = FileDeletion', { path: change.path, ino: change.ino }) - return [change, false] + return [change, undefined] } function fileUpdate(e /*: LocalFileUpdated */) { @@ -382,7 +382,7 @@ function fileUpdate(e /*: LocalFileUpdated */) { wip: change.wip }) - return [change, false] + return [change, undefined] } function fileMoveFromUnlinkAdd( @@ -417,7 +417,7 @@ function fileMoveFromUnlinkAdd( wip: fileMove.wip }) - return [fileMove, false] + return [fileMove, unlinkChange] } function dirMoveFromUnlinkAdd( @@ -446,7 +446,7 @@ function dirMoveFromUnlinkAdd( wip: dirMove.wip }) - return [dirMove, true] + return [dirMove, unlinkChange] } function fileMoveFromAddUnlink( @@ -455,6 +455,7 @@ function fileMoveFromAddUnlink( ) { const addChange /*: ?LocalFileAddition */ = maybeAddFile(sameInodeChange) if (!addChange) return + const fileMove /*: Object */ = build('FileMove', addChange.path, { stats: addChange.stats, md5sum: addChange.md5sum, @@ -470,7 +471,7 @@ function fileMoveFromAddUnlink( wip: fileMove.wip }) - return [fileMove, false] + return [fileMove, addChange] } function fileMoveFromFileDeletionChange( @@ -504,7 +505,7 @@ function fileMoveFromFileDeletionChange( } ) - return [fileMove, false] + return [fileMove, fileDeletion] } function dirMoveFromAddUnlink( @@ -528,7 +529,7 @@ function dirMoveFromAddUnlink( wip: dirMove.wip }) - return [dirMove, false] + return [dirMove, addChange] } function fileMoveIdentical( @@ -558,7 +559,7 @@ function fileMoveIdentical( wip: fileMove.wip }) - return [fileMove, false] + return [fileMove, addChange] } function fileRenamingCaseOnlyFromAddAdd( @@ -589,7 +590,7 @@ function fileRenamingCaseOnlyFromAddAdd( wip: fileMove.wip }) - return [fileMove, false] + return [fileMove, addChange] } function fileMoveIdenticalOffline(dstEvent /*: LocalFileAdded */) { @@ -616,7 +617,7 @@ function fileMoveIdenticalOffline(dstEvent /*: LocalFileAdded */) { wip: fileMove.wip }) - return [fileMove, false] + return [fileMove, undefined] } function dirRenamingCaseOnlyFromAddAdd( @@ -646,7 +647,7 @@ function dirRenamingCaseOnlyFromAddAdd( wip: dirMove.wip }) - return [dirMove, true] + return [dirMove, addChange] } function dirMoveIdenticalOffline(dstEvent /*: LocalDirAdded */) { @@ -672,7 +673,7 @@ function dirMoveIdenticalOffline(dstEvent /*: LocalDirAdded */) { wip: dirMove.wip }) - return [dirMove, false] + return [dirMove, undefined] } /*:: @@ -693,25 +694,23 @@ function includeAddEventInFileMove( moveChange.md5sum === e.md5sum ) return - moveChange.path = e.path - moveChange.stats = e.stats - moveChange.ino = e.stats.ino - moveChange.md5sum = e.md5sum - if (e.md5sum) { - delete moveChange.wip - } else { - moveChange.wip = true - } + const fileMove /*: Object */ = build('FileMove', e.path, { + stats: e.stats, + old: moveChange.old, + ino: e.stats.ino, + md5sum: e.md5sum + }) + if (!e.md5sum) fileMove.wip = true log.debug('FileMove + add = FileMove', { - oldpath: moveChange.old && moveChange.old.path, - path: moveChange.path, - ino: moveChange.ino, - wip: moveChange.wip + oldpath: fileMove.old && fileMove.old.path, + path: fileMove.path, + ino: fileMove.ino, + wip: fileMove.wip }) - return [moveChange, true] + return [fileMove, moveChange] } /** @@ -729,18 +728,23 @@ function dirMoveOverwriteOnMacAPFS( moveChange.path.normalize() === e.path.normalize() && moveChange.stats.ino === e.stats.ino ) { - moveChange.overwrite = true + const dirMove /*: Object */ = build('DirMove', moveChange.path, { + stats: e.stats, + old: moveChange.old, + ino: e.stats.ino, + overwrite: true + }) log.debug( 'DirMove(a, b) + addDir(b) = DirMove.overwrite(a, b) [chokidar bug]', { - oldpath: moveChange.old && moveChange.old.path, - path: moveChange.path, - ino: moveChange.ino + oldpath: dirMove.old && dirMove.old.path, + path: dirMove.path, + ino: dirMove.ino } ) - return [moveChange, true] + return [dirMove, moveChange] } } @@ -754,8 +758,7 @@ function dirRenamingIdenticalLoopback( moveChange.old && moveChange.old.path.normalize() === e.path.normalize() ) { - // $FlowFixMe - moveChange.type = 'Ignored' + const ignored = build('Ignored', moveChange.path) log.debug( `DirMove(a, b) + addDir(a) = Ignored(b, a) (identical renaming loopback)`, @@ -766,7 +769,7 @@ function dirRenamingIdenticalLoopback( } ) - return [moveChange, true] + return [ignored, moveChange] } } @@ -776,23 +779,21 @@ function includeAddDirEventInDirMove( ) { const moveChange /*: ?LocalDirMove */ = maybeMoveFolder(sameInodeChange) if (!moveChange) return - moveChange.path = e.path - moveChange.stats = e.stats - moveChange.ino = e.stats.ino - if (!e.wip) { - delete moveChange.wip - } else { - moveChange.wip = true - } + const dirMove /*: Object */ = build('DirMove', e.path, { + stats: e.stats, + old: moveChange.old, + ino: e.stats.ino + }) + if (e.wip) dirMove.wip = true log.debug('DirMove + addDir = DirMove', { - oldpath: moveChange.old && moveChange.old.path, - path: moveChange.path, - ino: moveChange.ino, - wip: moveChange.wip + oldpath: dirMove.old && dirMove.old.path, + path: dirMove.path, + ino: dirMove.ino, + wip: dirMove.wip }) - return [moveChange, true] + return [dirMove, moveChange] } function includeChangeEventIntoFileMove( @@ -801,134 +802,131 @@ function includeChangeEventIntoFileMove( ) { const moveChange /*: ?LocalFileMove */ = maybeMoveFile(sameInodeChange) if (!moveChange) return - moveChange.md5sum = e.md5sum - moveChange.update = _.defaults( - { - // In almost all cases, change event has the destination path. - // But on macOS identical renaming, it has the source path. - // So we make sure the file change being merged after the move - // won't erase the destination path with the source one. - // Should be a no-op on all other cases anyway, since e.path - // should already be the same as moveChange.path - path: moveChange.path - }, - e - ) - moveChange.stats = e.stats - moveChange.ino = e.stats.ino + + const fileMove /*: Object */ = build('FileMove', moveChange.path, { + stats: e.stats, + old: moveChange.old, + ino: e.stats.ino, + md5sum: e.md5sum, + update: _.defaults( + { + // In almost all cases, change event has the destination path. But on + // macOS identical renaming, it has the source path. So we make sure + // the file change being merged after the move won't erase the + // destination path with the source one. Should be a no-op on all other + // cases anyway, since e.path should already be the same as + // moveChange.path + path: moveChange.path + }, + e + ) + }) log.debug('FileMove + change', { - oldPath: moveChange.old && moveChange.old.path, - path: moveChange.path, - ino: moveChange.ino + oldPath: fileMove.old && fileMove.old.path, + path: fileMove.path, + ino: fileMove.ino }) - return [moveChange, true] + return [fileMove, moveChange] } function convertFileMoveToDeletion(samePathChange /*: ?LocalChange */) { - const change /*: ?LocalFileMove */ = maybeMoveFile(samePathChange) - if (change && change.wip && change.old) { - // $FlowFixMe - change.type = 'FileDeletion' - change.path = change.old.path - delete change.md5sum - delete change.stats - delete change.wip + const moveChange /*: ?LocalFileMove */ = maybeMoveFile(samePathChange) + if (moveChange && moveChange.wip && moveChange.old) { + const fileDeletion /*: Object */ = build( + 'FileDeletion', + moveChange.old.path, + { + old: moveChange.old, + ino: moveChange.ino + } + ) log.debug('FileMove + unlink = FileDeletion', { - path: change.path, - ino: change.ino + path: fileDeletion.path, + ino: fileDeletion.ino }) - return [change, true] + return [fileDeletion, moveChange] } } function convertDirMoveToDeletion(samePathChange /*: ?LocalChange */) { - const change /*: ?LocalDirMove */ = maybeMoveFolder(samePathChange) - if (change && change.old) { - // $FlowFixMe - change.type = 'DirDeletion' - change.path = change.old.path - delete change.stats - delete change.wip + const moveChange /*: ?LocalDirMove */ = maybeMoveFolder(samePathChange) + if (moveChange && moveChange.old) { + const dirDeletion /*: Object */ = build( + 'DirDeletion', + moveChange.old.path, + { + old: moveChange.old, + ino: moveChange.ino + } + ) log.debug('DirMove + unlinkDir = DirDeletion', { - path: change.path, - ino: change.ino + path: dirDeletion.path, + ino: dirDeletion.ino }) - return [change, true] + return [dirDeletion, moveChange] } } function ignoreDirAdditionThenDeletion(samePathChange /*: ?LocalChange */) { - const addChangeSamePath /*: ?LocalDirAddition */ = - maybePutFolder(samePathChange) - if (addChangeSamePath && addChangeSamePath.wip) { - // $FlowFixMe - addChangeSamePath.type = 'Ignored' + const addChange /*: ?LocalDirAddition */ = maybePutFolder(samePathChange) + if (addChange && addChange.wip) { + const ignored = build('Ignored', addChange.path) log.debug('Folder was added then deleted. Ignoring add.', { - path: addChangeSamePath.path, - ino: addChangeSamePath.ino + path: addChange.path, + ino: addChange.ino }) - return [addChangeSamePath, true] + return [ignored, addChange] } } function ignoreFileAdditionThenDeletion(samePathChange /*: ?LocalChange */) { - const addChangeSamePath /*: ?LocalFileAddition */ = - maybeAddFile(samePathChange) - if (addChangeSamePath && addChangeSamePath.wip) { - // $FlowFixMe - addChangeSamePath.type = 'Ignored' - delete addChangeSamePath.wip - delete addChangeSamePath.md5sum + const addChange /*: ?LocalFileAddition */ = maybeAddFile(samePathChange) + if (addChange && addChange.wip) { + const ignored = build('Ignored', addChange.path) log.debug('File was added then deleted. Ignoring add.', { - path: addChangeSamePath.path, - ino: addChangeSamePath.ino + path: addChange.path, + ino: addChange.ino }) - return [addChangeSamePath, true] + return [ignored, addChange] } } function ignoreUnmergedDirMoveThenDeletion(samePathChange /*: ?LocalChange */) { - const moveChangeSamePath /*: ?LocalDirMove */ = - maybeMoveFolder(samePathChange) - if (moveChangeSamePath && !moveChangeSamePath.old) { - // $FlowFixMe - moveChangeSamePath.type = 'Ignored' - delete moveChangeSamePath.wip + const moveChange /*: ?LocalDirMove */ = maybeMoveFolder(samePathChange) + if (moveChange && !moveChange.old) { + const ignored = build('Ignored', moveChange.path) log.debug('Folder was added then moved then deleted. Ignoring.', { - path: moveChangeSamePath.path, - ino: moveChangeSamePath.ino + path: moveChange.path, + ino: moveChange.ino }) - return [moveChangeSamePath, true] + return [ignored, moveChange] } } function ignoreUnmergedFileMoveThenDeletion( samePathChange /*: ?LocalChange */ ) { - const moveChangeSamePath /*: ?LocalFileMove */ = maybeMoveFile(samePathChange) - if (moveChangeSamePath && !moveChangeSamePath.old) { - // $FlowFixMe - moveChangeSamePath.type = 'Ignored' - delete moveChangeSamePath.wip - delete moveChangeSamePath.md5sum + const moveChange /*: ?LocalFileMove */ = maybeMoveFile(samePathChange) + if (moveChange && !moveChange.old) { + const ignored = build('Ignored', moveChange.path) log.debug('File was added then moved then deleted. Ignoring.', { - path: moveChangeSamePath.path, - ino: moveChangeSamePath.ino + path: moveChange.path, + ino: moveChange.ino }) - return [moveChangeSamePath, true] + return [ignored, moveChange] } } diff --git a/test/unit/local/chokidar/analysis.js b/test/unit/local/chokidar/analysis.js index d6eb37be8..790cddb59 100644 --- a/test/unit/local/chokidar/analysis.js +++ b/test/unit/local/chokidar/analysis.js @@ -53,9 +53,7 @@ onPlatform('darwin', () => { { sideName, type: 'Ignored', - path, - ino, - stats + path } ], pendingChanges: [] @@ -83,10 +81,7 @@ onPlatform('darwin', () => { { sideName, type: 'Ignored', - path: 'FOO', - stats, - ino: stats.ino, - old: undefined + path: 'FOO' } ], pendingChanges: [] @@ -114,10 +109,7 @@ onPlatform('darwin', () => { { sideName, type: 'Ignored', - path: 'FOO', - stats, - ino: stats.ino, - old: undefined + path: 'FOO' } ], pendingChanges: [] @@ -144,10 +136,7 @@ onPlatform('darwin', () => { { sideName, type: 'Ignored', - path: 'FOO', - stats, - ino: stats.ino, - old: undefined + path: 'FOO' } ], pendingChanges: [] @@ -174,10 +163,7 @@ onPlatform('darwin', () => { { sideName, type: 'Ignored', - path: 'FOO', - stats, - ino: stats.ino, - old: undefined + path: 'FOO' } ], pendingChanges: [] @@ -477,7 +463,6 @@ onPlatform('darwin', () => { sideName, type: 'FileMove', path: 'dst2', - md5sum: undefined, ino: 1, wip: true, stats, From 8151f6af4754a247b421d0554001195219c1bd1b Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Wed, 16 Oct 2024 12:32:58 +0200 Subject: [PATCH 3/4] WIP --- core/local/chokidar/analysis.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/local/chokidar/analysis.js b/core/local/chokidar/analysis.js index d028f01ca..bf58dcbff 100644 --- a/core/local/chokidar/analysis.js +++ b/core/local/chokidar/analysis.js @@ -72,7 +72,7 @@ module.exports = function analysis( class LocalChangeMap { /*:: - changes: LocalChange[] + changes: Set changesByInode: Map changesByPath: Map */ @@ -82,7 +82,7 @@ class LocalChangeMap { } _clear() { - this.changes = [] + this.changes = new Set() this.changesByInode = new Map() this.changesByPath = new Map() } @@ -108,8 +108,8 @@ class LocalChangeMap { if (typeof toReplace.ino === 'number') { this.changesByInode.set(toReplace.ino, c) } else { - const index = this.changes.indexOf(toReplace) - this.changes.splice(index, 1, c) + this.changes.delete(toReplace) + this.changes.add(c) } } else { this.changesByPath.set(c.path.normalize(), c) @@ -117,16 +117,16 @@ class LocalChangeMap { if (typeof c.ino === 'number') { this.changesByInode.set(c.ino, c) } else { - this.changes.push(c) + this.changes.add(c) } } } flush() /*: LocalChange[] */ { const changes = this.changes - for (let a of this.changesByInode.values()) changes.push(a) + for (let a of this.changesByInode.values()) changes.add(a) this._clear() - return changes + return Array.from(changes) } } @@ -157,7 +157,7 @@ function analyseEvents( log.trace('Analyze events...') - for (let e /*: LocalEvent */ of events) { + for (const e /*: LocalEvent */ of events) { if (process.env.DEBUG) log.trace({ currentEvent: e, path: e.path }) try { // chokidar make mistakes From 380b7207a7a40dd74eefba831e1445aefb9fbcb7 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Thu, 17 Oct 2024 15:27:21 +0200 Subject: [PATCH 4/4] WIP: 3.40.1-dev.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8c075011..a5d8fe404 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "CozyDrive", "productName": "Cozy Drive", "private": true, - "version": "3.40.0", + "version": "3.40.1-dev.1", "description": "Cozy Drive is a synchronization tool for your files and folders with Cozy Cloud.", "homepage": "https://github.com/cozy-labs/cozy-desktop", "author": "Cozy Cloud (https://cozycloud.cc/)",