Skip to content

create temp context correctly - #12339

Merged
cderv merged 4 commits into
mainfrom
bugfix/project-temp-cleanup-2
Mar 24, 2025
Merged

create temp context correctly#12339
cderv merged 4 commits into
mainfrom
bugfix/project-temp-cleanup-2

Conversation

@cscheid

@cscheid cscheid commented Mar 21, 2025

Copy link
Copy Markdown
Member

This is a followup fix to #12329.

Comment thread src/project/project-context.ts
Comment on lines 480 to +482
cleanup: () => {
context.diskCache.close();
temp.cleanup();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cleanup was for singleFile render associated to const temp = globalTempContext();
So as this is already cleaned up globally, I didn't think we needed to do manual temp.cleanup in this case.

TBH, having those two different tempContext is for now not easy for me to reason about. I guess cleaning up in this finally step will not prevent or mess the last cleanup

  1. Global cleanup register for quarto-session dir in TEMP

    onCleanup(cleanupSessionTempDir);

  2. Called in Exit cleanup

    export function onCleanup(handler: VoidFunction) {
    cleanupHandlers.push(handler);
    }
    export function exitWithCleanup(code: number) {
    // Not using cleanupHandlers.reverse() to not mutate the original array
    for (let i = cleanupHandlers.length - 1; i >= 0; i--) {
    const handler = cleanupHandlers[i];
    try {
    handler();
    } catch (error) {
    info("Error occurred during cleanup: " + error);
    }
    }
    Deno.exit(code);
    }

I guess this will be unused code now if we do cleanup as part of context.cleanup

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, having those two different tempContext is for now not easy for me to reason about.

The old code is (demonstrably, see this PR!) hard for me to reason about too...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually since this is also not a single-file render, I think we should replace globalTempContext() with a makeTempContext like we do in the other settings.

@cderv cderv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, to sum up, globalTempContext() is no longer used. Quarto will now store all temp files locally in .quarto.

For sure this is clearer to read as more scoped.

Still, I think we should watch out for the side effects of moving from the OS global TEMP folder to the project local folder. The period before the final release will be a good test!

@cscheid

cscheid commented Mar 21, 2025

Copy link
Copy Markdown
Member Author

Still, I think we should watch out for the side effects of moving from the OS global TEMP folder to the project local folder. The period before the final release will be a good test!

💯

@cderv
cderv merged commit 90d05e0 into main Mar 24, 2025
@cderv
cderv deleted the bugfix/project-temp-cleanup-2 branch March 24, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants