diff --git a/src/App.jsx b/src/App.jsx index 5c1c5d3a..6c554bce 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -59,7 +59,7 @@ import { getOutPath, toast, errorToast, handleError, setFileNameTitle, getOutDir, withBlur, checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile, isDurationValid, filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate, - havePermissionToReadFile, resolvePathIfNeeded, pathExists, html5ifiedPrefix, html5dummySuffix, findExistingHtml5FriendlyFile, + havePermissionToReadFile, resolvePathIfNeeded, getPathReadAccessError, html5ifiedPrefix, html5dummySuffix, findExistingHtml5FriendlyFile, deleteFiles, isStreamThumbnail, getAudioStreams, getVideoStreams, isOutOfSpaceError, shuffleArray, } from './util'; import { formatDuration } from './util/duration'; @@ -1502,11 +1502,17 @@ const App = memo(() => { return; } - if (!(await pathExists(path))) { - errorToast(i18n.t('The media you tried to open does not exist')); + const pathReadAccessErrorCode = await getPathReadAccessError(path); + if (pathReadAccessErrorCode != null) { + let errorMessage; + if (pathReadAccessErrorCode === 'ENOENT') errorMessage = i18n.t('The media you tried to open does not exist'); + else if (['EACCES', 'EPERM'].includes(pathReadAccessErrorCode)) errorMessage = i18n.t('You do not have permission to access this file'); + else errorMessage = i18n.t('Could not open media due to error {{errorCode}}', { errorCode: pathReadAccessErrorCode }); + errorToast(errorMessage); return; } + // Not sure why this one is needed, but I think sometimes fs.access doesn't fail but it fails when actually trying to read if (!(await havePermissionToReadFile(path))) { errorToast(i18n.t('You do not have permission to access this file')); return; diff --git a/src/util.js b/src/util.js index 9b948676..37eefed8 100644 --- a/src/util.js +++ b/src/util.js @@ -58,6 +58,15 @@ export async function pathExists(pathIn) { return fs.pathExists(pathIn); } +export async function getPathReadAccessError(pathIn) { + try { + await fs.access(pathIn, fs.constants.R_OK); + return undefined; + } catch (err) { + return err.code; + } +} + export async function dirExists(dirPath) { return (await pathExists(dirPath)) && (await fs.lstat(dirPath)).isDirectory(); }