Skip to content

Commit

Permalink
Improve file handling when some other process is grabbing our files
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Jun 8, 2024
1 parent e6887d7 commit 5d24333
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
21 changes: 16 additions & 5 deletions src/components/Notify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export function NotifyRenameProblem(err: any, path: string) {
function getEBUSYProblemsTips(): JSX.Element {
return (
<ul>
<li>
Are your files managed by a synchronization software like OneDrive or
Dropbox? These programs can grab onto lameta files and interfere.
</li>
<li>
Is the file open in another program? If not, try restarting your
computer.
Expand All @@ -93,10 +97,6 @@ function getEBUSYProblemsTips(): JSX.Element {
Is your anti-virus interfering with lameta? Normally there is a way to
tell it that lameta is safe.
</li>
<li>
Are your files managed by a synchronization software like Dropbox?
Normally this kind of problem will resolve itself.
</li>
</ul>
);
}
Expand All @@ -105,6 +105,11 @@ function getEBUSYProblemsTips(): JSX.Element {
function getEACCESProblemsTips(): JSX.Element {
return (
<ul>
{/* I get this error with file meddler grabbing, thus this message */}
<li>
Are your files managed by a synchronization software like OneDrive or
Dropbox? These programs can grab onto lameta files and interfere.
</li>
<li>
Is your anti-virus interfering with lameta? Normally there is a way to
tell it that lameta is safe.
Expand Down Expand Up @@ -199,6 +204,12 @@ export function NotifyNoBigDeal(message: string, onClick?: () => void) {
}),
0
);
// remove any existing messages of this type
window.setTimeout(() => {
ButterToast.dismissAll((toast) => {
return toast.scheme === Cinnamon.Crunch.SCHEME_GREY;
});
}, 0);
}

export function NotifyWarning(message: string, onClick?: () => void) {
Expand Down Expand Up @@ -269,7 +280,7 @@ export function NotifyMultipleProjectFiles(
window.setTimeout(
() =>
NotifyWarning(
t`There is a problem with ${displayName}. Click for more information.`,
t`There is a problem with the files in the folder for ${displayName}. Click for more information.`,
() => {
electron.ipcRenderer
.invoke("showMessageBox", {
Expand Down
14 changes: 8 additions & 6 deletions src/other/patientFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { t } from "@lingui/macro";
extensive. Keeping this around for now because there is some question about some
windows corner-cases in the graceful-fs system.
But I'm reducing the number of retry attempts to just 1 for now.
UPDATE: It turns out that graceful-fs is only prevents contention between threads,
not with other processes.
*/

export class PatientFS {
Expand Down Expand Up @@ -98,21 +100,20 @@ export class PatientFS {
}
private static patientFileOperationSync(operation: () => any): any {
// note, graceful-fs is already pausing up to 60 seconds on each attempt.
// So even 2 attempts may be too much.
const kattempts = 2;
const kattempts = 5;
let attempt = 1;
for (; attempt <= kattempts; attempt++) {
try {
const result = operation();
if (attempt > 1) {
// there is no way to asynchronously show any UI, but after a long wait in which we finally got through, it might help to tell people what caused the a delay.
NotifyNoBigDeal(
`There was a delay in reading a file... perhaps another program, file sync service, or antivirus is interfering.`
`There was a delay in accessing a file... perhaps another program, file sync service, or antivirus is interfering.`
);
}
return result;
} catch (err) {
if (err.code === "EBUSY") {
if (err.code === "EBUSY" || err.code === "EPERM") {
if (attempt === kattempts) {
throw err; // give up
}
Expand All @@ -126,8 +127,9 @@ export class PatientFS {
}

private static sleepForShortWhile() {
console.error("patientFile:sleepForShortWhile");
//"sleep" would probably work on mac/linux. But the equivalent "timeout" on windows fails when there is no keyboad input.
// So we're doing a ping. Note tha a pint of "-n 1" is 0ms on windows, oddly, while "-n 2" takes about a second
// So we're doing a ping. Note that a ping of "-n 1" is 0ms on windows, oddly, while "-n 2" takes about a second
child_process.spawnSync("ping", ["-n 2 127.0.0.1"], {
shell: true
});
Expand Down

0 comments on commit 5d24333

Please sign in to comment.