Skip to content

Commit

Permalink
Merge pull request #492 from justinlampley/FixPIOInstallPathTooLong
Browse files Browse the repository at this point in the history
Platform IO installer fails if the path to the installer temporary directory is too long
  • Loading branch information
jurgelenas authored Apr 27, 2023
2 parents 422b96f + 8acd4a0 commit f8a5e89
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ 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;

if (isWindows) {
const dirtyUserDataDirectory = app.isPackaged
Expand Down Expand Up @@ -243,9 +243,41 @@ 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.
*/
Expand Down

0 comments on commit f8a5e89

Please sign in to comment.