Skip to content

Studio: Fix no directory or file error on Windows - #1391

Merged
katinthehatsite merged 3 commits into
trunkfrom
fix/no-directory-file-error
May 16, 2025
Merged

Studio: Fix no directory or file error on Windows#1391
katinthehatsite merged 3 commits into
trunkfrom
fix/no-directory-file-error

Conversation

@katinthehatsite

@katinthehatsite katinthehatsite commented May 14, 2025

Copy link
Copy Markdown
Contributor

Related issues

Fixes STU-442

Proposed Changes

I could not reproduce this issue on Windows on my end but I noticed that several issues in Sentry point to downloadWordPress function in vendor/wp-now/src/download.ts. Specifically, the error seems to happen when there is a creation or interaction with the temporary directory that is used to store downloaded WordPress before moving it to final folder.

Running through Sentry errors, I noticed that we always place wordpress like this:

  • C:\Users\USERNAME\AppData\Local\Temp\wordpress on Windows
  • /var/folders/bj/{userSessionToken}/T/wordpress on macOS

My suspicion is that sometimes there might be multiple processes that are downloading WordPress at the same time which could create some conflicts with the temporary directory as it is now. In this PR, I suggest that we use unique parent directories for each download process so that it does not create those possible conflicts. After modification, each process would get its own unique path such as (example below is for Windows):

  C:\Users\USERNAME\AppData\Local\Temp\wordpress-download-xwfmXp\wordpress - Process 1
  C:\Users\USERNAME\AppData\Local\Temp\wordpress-download-ZhuU1E\wordpress - Process 2

We will also clean up these temporary directories once WordPress is moved from them to the final destination.

Testing Instructions

I think it would be sufficient to test adding a site with different WordPress versions that you don't have installed under /Library/Application Support/Studio/server-files/wordpress-version and confirm that the site is created successfully. But if you want to see some behind the scenes, you can use these steps:

  • Pull the changes from this branch
  • Apply the following diff:
index d82c9c40..b0ac8652 100644
--- a/vendor/wp-now/src/download.ts
+++ b/vendor/wp-now/src/download.ts
@@ -157,6 +157,7 @@ export async function downloadWordPress(
 ) {
        const finalFolder = getWordPressVersionPath( wordPressVersion );
        const tempDir = await fs.mkdtemp( path.join( os.tmpdir(), 'wordpress-download-' ) );
+       console.log( 'Temporary directory path:', tempDir );
 
        try {
                const { downloaded, statusCode } = await downloadFileAndUnzip( {
  • Start the app with npm start (if switching directly from trunk, make sure to restart the app as we are modifying the main process)
  • Observe the location of the temporary directory in the logs in your terminal where you started Studio. It will look something like: /var/folders/bj/1qgxs1qd6_z20tw9llkw842h0000gn/T
  • Run in a Terminal on macOS open /var/folders/bj/1qgxs1qd6_z20tw9llkw842h0000gn/T/ (replace with your path that you got in the previous step)
  • Back in Studio, click on Add site and select a WP version that you don't have added under /Library/Application Support/Studio/server-files/wordpress-version
  • Observe that once the download process starts, you can see a sub-directory created under /var/folders/bj/1qgxs1qd6_z20tw9llkw842h0000gn/T/. It should have a structure similar to /wordpress-download-{randomLetters}.
  • Confirm that once the download is completed, the sub-directory is removed
  • Confirm that the site gets added and starts successfully

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@katinthehatsite katinthehatsite self-assigned this May 14, 2025
@katinthehatsite
katinthehatsite marked this pull request as draft May 14, 2025 11:32
@katinthehatsite katinthehatsite changed the title Fix no directory or file error on Windows May 14, 2025
@katinthehatsite
katinthehatsite marked this pull request as ready for review May 14, 2025 12:47
@katinthehatsite
katinthehatsite requested a review from a team May 14, 2025 12:47

@gavande1 gavande1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think your observation is spot-on. The errors indicate a problem with cleaning up the temporary folder. The changes look good to me! 👍

I would wait a few days before closing the Linear issue since we are not sure if this PR will actually fix the problem.

@fredrikekelund fredrikekelund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, the theory is that if users create multiple sites in quick succession with a WordPress version that wasn't downloaded before they created the first site, multiple downloadWordPress calls will get kicked off simultaneously, causing them to modify the same files, right? This seems like a reasonable theory to me, and the use of fs.mkdtemp is a good way to mitigate that.

I came to think of the sequential helper in src/lib/proxy-server.ts, but I don't think it would add much here. This solution covers the needs here already. I've also tested it, and it works well 👍

One question that came up for me is whether we really need to call downloadWordPress in the startWPNow function..? Haven't we already guaranteed that WordPress is installed in the project directory at that point?

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

I would wait a few days before closing the Linear issue since we are not sure if this PR will actually fix the problem.

Sounds good, I was going to double-check on Slack at first to see what is the process for this and what steps we need to take in Sentry.

@fredrikekelund

Copy link
Copy Markdown
Contributor

Looking up all the related Sentry issues might be a hassle, because I know there were multiple ones, but Sentry has a feature to mark issues as resolved in the next release. That would be a very good fit for this scenario, and it gives us an alert if it turns out the same errors continue appearing in the next release, so it increases visibility.

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

So, the theory is that if users create multiple sites in quick succession with a WordPress version that wasn't downloaded before they created the first site, multiple downloadWordPress calls will get kicked off simultaneously, causing them to modify the same files, right?

Yeah, I inferred this from the fact that the error was always similar and was always related to some file missing but it was never exactly the same file. I also saw some logs related to auto-updates on one of the error instances in Sentry which made me think that two processes could be using the downloadWordPress function at once.

One question that came up for me is whether we really need to call downloadWordPress in the startWPNow function..? Haven't we already guaranteed that WordPress is installed in the project directory at that point?

I did not look too closely into that bit. From quick look, it might be but we if we want to clean it up, we should double-check the whole flow to make sure nothing breaks and can clean it up after. We can open an issue to look through this. Regardless, I think the changes from this PR would be useful.

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

Looking up all the related Sentry issues might be a hassle, because I know there were multiple ones, but Sentry has a feature to mark issues as resolved in the next release. That would be a very good fit for this scenario, and it gives us an alert if it turns out the same errors continue appearing in the next release, so it increases visibility.

I will take a look, thanks 👀

@katinthehatsite
katinthehatsite merged commit 7423bdf into trunk May 16, 2025
@katinthehatsite
katinthehatsite deleted the fix/no-directory-file-error branch May 16, 2025 09:40
@katinthehatsite

Copy link
Copy Markdown
Contributor Author

Added STU-509 to check the data flow for downloadWordPress in startWPNow.

bcotrim pushed a commit that referenced this pull request May 27, 2025
* Fix no directory or file error on Windows

* Cleanup directories

---------

Co-authored-by: Kateryna Kodonenko <kateryna@automattic.com>
bcotrim added a commit that referenced this pull request May 27, 2025
commit d31733b
Author: katinthehatsite <katerynakodonenko@gmail.com>
Date:   Tue May 27 09:12:55 2025 +0200

    Studio: Delete old proof-of-concept WP-CLI implementation (#1426)

    * Remove old scripts

    * Remove old cli.ts

    * Cleanup tests

    * Clean up terminal opening and feature flag

    * Cleanup assistant code

    * Clean shortcuts code

    * Cleanup feature flags

    * Cleanup feature flags

    * Cleanup shortcuts sessions

    * Removed unused feature flag for assistant

    * Assistant code block test fix

    * Adjust preload

    * Cleanup index file and tests

    * Refactor terminal usage

    * Add back the lock

    * Remove unintended change

    * Remove unnecesary type for warp

    * Use bundled Ids

    * Cleanup event parameter

    ---------

    Co-authored-by: Kateryna Kodonenko <kateryna@automattic.com>

commit 4fac446
Author: Volodymyr Makukha <nei.css@gmail.com>
Date:   Mon May 26 20:19:35 2025 +0100

    Update Ukrainian translations - May 26 (#1439)

commit c7536ef
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Mon May 26 18:34:28 2025 +0100

    Load LTR and RTL stylesheets conditionally (#1429)

    * Add a new component
    * Load @wordpress/components css conditionally based on RTL and LTR.
    * Load index.css a.k.a main_window.css after loading the WordPress stylesheet

commit c80b70e
Author: Bero <berislav.grgicak@gmail.com>
Date:   Mon May 26 19:20:42 2025 +0200

    Update Playground packages to 1.0.38 and remove the Symlink manager (#1425)

    * Update Playground packages to 1.0.38
    * Remove SymlinkManager
    * Activate Playground's followSymlinks feature
    * Remove @php-wasm/universal patch

commit 5bfe676
Author: Wojtek Naruniec <wojtek.naruniec@automattic.com>
Date:   Mon May 26 15:40:18 2025 +0200

    Sanitize regex in Win editor path (#1411)

    * Sanitize regex

    * Import only escapeRegExp function

commit 2cd3e44
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Mon May 26 13:18:02 2025 +0200

    Bump version from 1.5.2-beta4 to 1.5.2 (#1436)

commit f16865e
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Mon May 26 12:38:24 2025 +0200

    Add release notes for 1.5.2 (#1434)

    * Add release notes for 1.5.2

    * Reorder release notes

    * Update release notes order and formatting

    * Added latest UI fix to the release notes

    * Consolidate Studio CLI fixes into a single bullet point

commit f6e48d5
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Mon May 26 12:21:30 2025 +0200

    Add translations for 1.5.2 (#1433)

    * Add translations for 1.5.2

    * Add latest Polish and Spanish translations

    * Update spanish translations

    ---------

    Co-authored-by: Antonio Sejas <antonio@sejas.es>

commit ae1d163
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Mon May 26 10:58:22 2025 +0100

    Share same styles between preview and sync tabs (#1435)

commit d6a7905
Author: Roberto Aranda <roberto.aranda@automattic.com>
Date:   Fri May 23 15:23:14 2025 +0200

    Return original URL param when it cannot be parsed (#1420)

    * Return the passed URL parameter when it cannot be parsed instead of an empty string

commit 91d04be
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Fri May 23 14:22:34 2025 +0100

    Update localized docs links for Studio Sync  and Studio CLI (#1431)

    * Add translation link to new Spanish studio docs CLI
    * Add hash to Studio sync supported sites

commit 6213094
Author: katinthehatsite <katerynakodonenko@gmail.com>
Date:   Fri May 23 14:27:53 2025 +0200

    Add patch to fix the accessibility with modals (#1423)

    Co-authored-by: Kateryna Kodonenko <kateryna@automattic.com>

commit b2724c0
Author: Rahul Gavande <rahul.gavande@automattic.com>
Date:   Fri May 23 14:45:11 2025 +0530

    Use uri scheme to open Warp terminal app (#1428)

commit 43c831b
Author: Fredrik Rombach Ekelund <fredrik@f26d.dev>
Date:   Wed May 21 16:10:40 2025 +0200

    CLI: Set UTF8 encoding for output on Windows (#1424)

commit b1c0eeb
Author: Volodymyr Makukha <nei.css@gmail.com>
Date:   Wed May 21 10:34:47 2025 +0100

    Fix hiding plugins spinner (#1419)

commit 48988ed
Author: Fredrik Rombach Ekelund <fredrik@f26d.dev>
Date:   Wed May 21 10:31:33 2025 +0200

    Add migration to rename launch uniques stat (#1415)

    * Add migration to rename launch uniques stat

    * Fix CLI zod schema

commit f363144
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Tue May 20 18:24:00 2025 +0200

    Bump version to 1.5.2-beta4 (#1421)

commit 9768e67
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Tue May 20 15:29:33 2025 +0200

    Pressable Sync: Fix remaining Sync modal issues (#1416)

    * Use absolute path for `WordPressLogoCircle` import

    * Use separate `isDisabled` to makde WP logo gray

    * Remove trailing space in site selector helper text

    * Decrease font size of sync sites modal learn more link

commit 9fab398
Author: Ian G. Maia <iangmaia@users.noreply.github.com>
Date:   Tue May 20 13:15:23 2025 +0200

    [Tooling] Update code to DRY the Windows build PS1 (#1408)

    * Update code to DRY the Windows build PS1

    * Update case of `Exit` command

    * Use `windows` instead of just `win` to prefix windows-related scripts

    * Add $LastExitCode check after `npm run make`

commit e5d4006
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Tue May 20 12:01:21 2025 +0200

    Improve version comparison logic to handle prerelease transitions correctly (#1403)

commit f0a282b
Author: Rahul Gavande <rahul.gavande@automattic.com>
Date:   Tue May 20 15:15:25 2025 +0530

    HTTPS: Convert domain name Unicode characters to ASCII characters (#1400)

    * Convert domain name unicode chars to ASCII

    * Do not use punnycode domain name for paths

    * Remove unncessary punnycode domain name

commit 6cdc351
Author: Roberto Aranda <roberto.aranda@automattic.com>
Date:   Tue May 20 11:35:52 2025 +0200

    Sync: Update notification to include Hostname (#1412)

    * Push: Update notification to include Hostname

    * Pull: Update notification to include hostname

    * Add hints for translators

commit 69419a6
Author: Gergely Csécsey <gergely.csecsey@automattic.com>
Date:   Tue May 20 10:30:57 2025 +0100

    Increase HTTP request timeout to 60 seconds (#1407)

    * Increase HTTP request timeout to 60 seconds

    * Increase curl timeout to 60 seconds

    * update comments

commit 6bcbbff
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Tue May 20 09:36:18 2025 +0100

    Update connect site text button when connecting another site (#1413)

    * Adapt the "Connect Site" button when connecting multiple sites on Sync.

commit 60a9cab
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Tue May 20 09:10:37 2025 +0100

    Avoid orphan in sync title (#1414)

commit 3b103cc
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Mon May 19 10:39:12 2025 +0100

    Release 1.5.2-beta3 (#1410)

commit a109671
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Mon May 19 09:45:17 2025 +0200

    Sync: Update sync tab text and remove WordPress logo from title (#1405)

    * Update sync tab text and remove WordPress logo from title

    * Fix related test

    * Use comma

    * Update copy of the bullet points

    * Replace `WP.com` with `WordPress.com`.

    Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>

    * Replace WP.com with WordPress.com

    Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>

    * Delete unused WordPress short logo component

    ---------

    Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>

commit 716bc7a
Author: Ivan Ottinger <ivan.ottinger@automattic.com>
Date:   Fri May 16 16:15:16 2025 +0200

    Sync: Update Sync modal content (#1406)

    * Update WordPress logo component `viewBox`

    * Update Sync modal heading

    * Update text below Sync search field

    * Update Sync modal site logos

    * Replace hardcoded arrows with `ArrowIcon` component in sync sites modal links

    * Localize sync modal Read more link using `getLocalizedLink` utility

commit 11b4302
Author: Roberto Aranda <roberto.aranda@automattic.com>
Date:   Fri May 16 15:14:40 2025 +0200

    Push: Read and update the progress from the sync endpoint (#1389)

    * Calls the GET /sync/import using the importId to obtain the progress
    * Use the progress from the /sync/import endpoint to update the progress in the importing state
    * Splits the progress of the importing state between backup and import

commit 7423bdf
Author: katinthehatsite <katerynakodonenko@gmail.com>
Date:   Fri May 16 11:40:18 2025 +0200

    Studio: Fix no directory or file error on Windows (#1391)

    * Fix no directory or file error on Windows

    * Cleanup directories

    ---------

    Co-authored-by: Kateryna Kodonenko <kateryna@automattic.com>

commit 1661ac4
Author: Antonio Sejas <antonio.sejas@automattic.com>
Date:   Fri May 16 10:04:32 2025 +0100

    Force display of what's new for minor version (#1404)

    * Force what's new display for minor version
    * Skip test that compares the patch version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants