Skip to content

Commit

Permalink
Merge pull request desktop#19227 from desktop/use-lstat-not-stat
Browse files Browse the repository at this point in the history
Revert some custom integration changes and use lstat instead of stat
  • Loading branch information
sergiou87 committed Sep 9, 2024
1 parent 59446af commit 0b64c23
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/src/lib/custom-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseCommandLineArgv } from 'windows-argv-parser'
import stringArgv from 'string-argv'
import { promisify } from 'util'
import { exec } from 'child_process'
import { access, stat } from 'fs/promises'
import { access, lstat } from 'fs/promises'
import * as fs from 'fs'

const execAsync = promisify(exec)
Expand Down Expand Up @@ -100,22 +100,22 @@ export async function validateCustomIntegrationPath(
let bundleID = undefined

try {
const pathStat = await lstat(path)
const canBeExecuted = await access(path, fs.constants.X_OK)
.then(() => true)
.catch(() => false)

const isExecutableFile =
(pathStat.isFile() || pathStat.isSymbolicLink()) && canBeExecuted

// On macOS, not only executable files are valid, but also apps (which are
// directories with a `.app` extension and from which we can retrieve
// the app bundle ID)
if (__DARWIN__ && !canBeExecuted) {
const pathStat = await stat(path)

if (pathStat.isDirectory()) {
bundleID = await getAppBundleID(path)
}
if (__DARWIN__ && !isExecutableFile && pathStat.isDirectory()) {
bundleID = await getAppBundleID(path)
}

return { isValid: canBeExecuted || !!bundleID, bundleID }
return { isValid: isExecutableFile || !!bundleID, bundleID }
} catch (e) {
log.error(`Failed to validate path: ${path}`, e)
return { isValid: false }
Expand Down

0 comments on commit 0b64c23

Please sign in to comment.