From 86da6493a41ca808ef87f7ab12bd1fa50e1b8ca2 Mon Sep 17 00:00:00 2001 From: Justin <38869875+justinlampley@users.noreply.github.com> Date: Tue, 25 Apr 2023 19:00:47 -0400 Subject: [PATCH 1/2] Platform IO installer fails on Windows if the path to the installer temporary directory is too long --- src/main.dev.ts | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main.dev.ts b/src/main.dev.ts index 44fda801b..f4aa356b2 100644 --- a/src/main.dev.ts +++ b/src/main.dev.ts @@ -69,7 +69,10 @@ function isASCII(str: string) { const isWindows = process.platform.startsWith('win'); const isMacOS = process.platform.startsWith('darwin'); let userDataDirectory = app.getPath('userData'); -const forceDirtyPath = true; +const forceDirtyPath = false; + +/* Set the temp directory for the PlatformIO Installer */ +process.env.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; if (isWindows) { const dirtyUserDataDirectory = app.isPackaged @@ -96,6 +99,36 @@ if (isWindows) { } ); } + + process.env.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; + + const publicFolder = 'C:\\Users\\Public'; + try { + // As of 2023-04-25, Platform IO installer fails on "building wheel for platformio" + // if the path to the installer temporary directory is too long, so use the Public + // User folder instead of the app data directory + if (fs.existsSync(publicFolder)) { + const testFile = path.join(publicFolder, `${Date.now()}.txt`); + fs.writeFileSync(testFile, ''); + fs.unlinkSync(testFile); + process.env.PLATFORMIO_INSTALLER_TMPDIR = publicFolder; + logger.log( + `using public folder ${publicFolder} for PlatformIO Installer` + ); + } else { + logger.log( + `using appdata path ${userDataDirectory} for PlatformIO Installer` + ); + } + } catch (err) { + logger.error( + `${publicFolder} not writable, using ${userDataDirectory} for PlatformIO Installer`, + undefined, + { + err, + } + ); + } } // eslint-disable-next-line @typescript-eslint/ban-types @@ -244,7 +277,6 @@ const createWindow = async () => { ); const localApiServerEnv = process.env; - localApiServerEnv.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; /* We manually prepend $PATH on Windows and macOS machines with portable Git and Python locations. From 8acd4a0ddf646dbcdf82ca9049c8ffdb1f8d866b Mon Sep 17 00:00:00 2001 From: Justin <38869875+justinlampley@users.noreply.github.com> Date: Wed, 26 Apr 2023 17:37:05 -0400 Subject: [PATCH 2/2] Set PLATFORMIO_INSTALLER_TMPDIR on localApiServerEnv instead of process.env --- src/main.dev.ts | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main.dev.ts b/src/main.dev.ts index f4aa356b2..8939872e0 100644 --- a/src/main.dev.ts +++ b/src/main.dev.ts @@ -71,9 +71,6 @@ const isMacOS = process.platform.startsWith('darwin'); let userDataDirectory = app.getPath('userData'); const forceDirtyPath = false; -/* Set the temp directory for the PlatformIO Installer */ -process.env.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; - if (isWindows) { const dirtyUserDataDirectory = app.isPackaged ? path.join('c:', `.${packageJson.name}`) @@ -99,36 +96,6 @@ if (isWindows) { } ); } - - process.env.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; - - const publicFolder = 'C:\\Users\\Public'; - try { - // As of 2023-04-25, Platform IO installer fails on "building wheel for platformio" - // if the path to the installer temporary directory is too long, so use the Public - // User folder instead of the app data directory - if (fs.existsSync(publicFolder)) { - const testFile = path.join(publicFolder, `${Date.now()}.txt`); - fs.writeFileSync(testFile, ''); - fs.unlinkSync(testFile); - process.env.PLATFORMIO_INSTALLER_TMPDIR = publicFolder; - logger.log( - `using public folder ${publicFolder} for PlatformIO Installer` - ); - } else { - logger.log( - `using appdata path ${userDataDirectory} for PlatformIO Installer` - ); - } - } catch (err) { - logger.error( - `${publicFolder} not writable, using ${userDataDirectory} for PlatformIO Installer`, - undefined, - { - err, - } - ); - } } // eslint-disable-next-line @typescript-eslint/ban-types @@ -276,7 +243,40 @@ const createWindow = async () => { 'platformio-temp-state-storage' ); - const localApiServerEnv = process.env; + const localApiServerEnv = { ...process.env }; + + /* Set the temp directory for the PlatformIO Installer */ + localApiServerEnv.PLATFORMIO_INSTALLER_TMPDIR = userDataDirectory; + + if (isWindows) { + const publicFolder = 'C:\\Users\\Public'; + try { + // As of 2023-04-25, Platform IO installer fails on "building wheel for platformio" + // if the path to the installer temporary directory is too long, so use the Public + // User folder instead of the app data directory + if (fs.existsSync(publicFolder)) { + const testFile = path.join(publicFolder, `${Date.now()}.txt`); + fs.writeFileSync(testFile, ''); + fs.unlinkSync(testFile); + localApiServerEnv.PLATFORMIO_INSTALLER_TMPDIR = publicFolder; + logger.log( + `using public folder ${publicFolder} for PlatformIO Installer` + ); + } else { + logger.log( + `using appdata path ${userDataDirectory} for PlatformIO Installer` + ); + } + } catch (err) { + logger.error( + `${publicFolder} not writable, using ${userDataDirectory} for PlatformIO Installer`, + undefined, + { + err, + } + ); + } + } /* We manually prepend $PATH on Windows and macOS machines with portable Git and Python locations.