-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Fixes #9779: Linux: Fix bundled Simple Backup can't create 7…
…zip archives (#9780)
- Loading branch information
1 parent
7b06090
commit da4d57c
Showing
6 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/app-desktop/utils/7zip/getPathToExecutable7Zip.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Setting from '@joplin/lib/models/Setting'; | ||
import pathToBundled7Zip from './pathToBundled7Zip'; | ||
import { join } from 'path'; | ||
import shim from '@joplin/lib/shim'; | ||
|
||
const pathTo7Za_: undefined|string = undefined; | ||
|
||
const getPathToExecutable7Zip = async () => { | ||
if (pathTo7Za_) { | ||
return pathTo7Za_; | ||
} | ||
|
||
const { baseDir: bundled7ZipDir, executableName, fullPath: bundled7ZipExecutablePath } = pathToBundled7Zip(); | ||
let pathTo7Za = bundled7ZipExecutablePath; | ||
|
||
// On Linux (and perhaps Free/OpenBSD?), the bundled 7zip binary can't be executed | ||
// in its default location and must be moved. | ||
if (!shim.isMac() && !shim.isWindows()) { | ||
const targetDir = join(Setting.value('cacheDir'), '7zip'); | ||
|
||
const fsDriver = shim.fsDriver(); | ||
const executablePath = join(targetDir, executableName); | ||
|
||
let needsUpdate; | ||
|
||
// The 7Zip binary may already be copied, in which case, it may not need to be updated. | ||
if (await shim.fsDriver().exists(targetDir)) { | ||
const currentChecksum = await fsDriver.md5File(executablePath); | ||
const bundledChecksum = await fsDriver.md5File(bundled7ZipExecutablePath); | ||
|
||
if (currentChecksum !== bundledChecksum) { | ||
needsUpdate = true; | ||
await shim.fsDriver().remove(targetDir); | ||
} else { | ||
needsUpdate = false; | ||
} | ||
} else { | ||
needsUpdate = true; | ||
} | ||
|
||
if (needsUpdate) { | ||
await shim.fsDriver().mkdir(targetDir); | ||
await shim.fsDriver().copy(bundled7ZipDir, targetDir); | ||
|
||
// Make executable. | ||
// Self: read+write+execute | ||
// Group: read+execute | ||
// Other: none | ||
await shim.fsDriver().chmod(executablePath, 0o750); | ||
} | ||
|
||
pathTo7Za = executablePath; | ||
} | ||
|
||
return pathTo7Za; | ||
}; | ||
|
||
export default getPathToExecutable7Zip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { join, resolve, basename, dirname } from 'path'; | ||
|
||
const pathToBundled7Zip = () => { | ||
// 7zip-bin is very large -- return the path to a version of 7zip | ||
// copied from 7zip-bin. | ||
const executableName = process.platform === 'win32' ? '7za.exe' : '7za'; | ||
|
||
let rootDir = dirname(dirname(__dirname)); | ||
|
||
// When bundled, __dirname points to a file within app.asar. The build/ directory | ||
// is outside of app.asar, and thus, we need an extra dirname(...). | ||
if (basename(rootDir).startsWith('app.asar')) { | ||
rootDir = dirname(rootDir); | ||
} | ||
|
||
const baseDir = join(rootDir, 'build', '7zip'); | ||
|
||
return { baseDir, executableName, fullPath: resolve(join(baseDir, executableName)) }; | ||
}; | ||
|
||
export default pathToBundled7Zip; |