Skip to content

The swiss army knife of lossless video/audio editing

Improve error when not access to opened file

Mikael Finstada319782a1e32
diff --git a/src/App.jsx b/src/App.jsx
index ee318cd7..75af9f24 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -51,7 +51,7 @@ import {
getOutPath, formatDuration, toast, errorToast, showFfmpegFail, setFileNameTitle, getOutDir, withBlur,
checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile,
isDurationValid, isWindows, filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate,
- hasDuplicates,
+ hasDuplicates, havePermissionToReadFile,
} from './util';
import { askForOutDir, askForImportChapters, createNumSegments, createFixedDurationSegments, promptTimeOffset, askForHtml5ifySpeed, askForYouTubeInput, askForFileOpenAction, confirmExtractAllStreamsDialog, cleanupFilesDialog, showDiskFull, showCutFailedDialog } from './dialogs';
import { openSendReportDialog } from './reporting';
@@ -1498,6 +1498,11 @@ const App = memo(() => {
return;
}
+ if (!(await havePermissionToReadFile(firstFile))) {
+ errorToast(i18n.t('You do not have permission to access this file'));
+ return;
+ }
+
const { newCustomOutDir, cancel } = await assureOutDirAccess(firstFile);
if (cancel) return;
diff --git a/src/util.js b/src/util.js
index 4bc68e64..eb2b1397 100644
--- a/src/util.js
+++ b/src/util.js
@@ -59,6 +59,21 @@ export function getOutPath(customOutDir, filePath, nameSuffix) {
return path.join(getOutDir(customOutDir, filePath), `${parsed.name}-${nameSuffix}`);
}
+export async function havePermissionToReadFile(filePath) {
+ try {
+ const fd = await fs.open(filePath, 'r');
+ try {
+ await fs.close(fd);
+ } catch (err) {
+ console.error('Failed to close fd', err);
+ }
+ } catch (err) {
+ if (['EPERM', 'EACCES'].includes(err.code)) return false;
+ console.error(err);
+ }
+ return true;
+}
+
export async function checkDirWriteAccess(dirPath) {
try {
await fs.access(dirPath, fs.constants.W_OK);