Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Temp file not working electron #176

Closed
1 of 8 tasks
do-web opened this issue Sep 19, 2018 · 7 comments · Fixed by #177
Closed
1 of 8 tasks

Windows Temp file not working electron #176

do-web opened this issue Sep 19, 2018 · 7 comments · Fixed by #177

Comments

@do-web
Copy link

do-web commented Sep 19, 2018

Operating System

  • Linux
  • Windows 7
  • Windows 10
  • MacOS
  • other:

NodeJS Version

  • 0.x
  • 4.x
  • 6.x
  • 7.x
  • other: 8.6

Tmp Version

TBD:Enter tmp version here
newest

Expected Behavior

TBD:What have you expected tmp to do?
correct temp file.

Experienced Behavior

TBD:What did actually happen?

It generates this file:

let fileName = tmp.tmpNameSync();
undefined\temp\tmp-3476obo4mLnOL8Bp

Then i trying to write to this file:

fs.writeFileSync(fileName, new Buffer(result.data));
no such file or directory, open 'C:\Users\xxx\xx\app-1.0.2\undefined\temp\tmp-3476obo4mLnOL8Bp'
@raszi
Copy link
Owner

raszi commented Sep 21, 2018

According to the source of os-tmpdir this could only happen if neither of the following environment variables are set: TEMP, TMP, SystemRoot, and windir.

Could you verify that for me please by dumping the process.env.

The following should work:

console.log(JSON.stringify(process.env))

@raszi
Copy link
Owner

raszi commented Sep 21, 2018

Could you please also show me what os.tmpdir() says to you?

const os = require('os');
console.log(os.tmpdir());

@do-web
Copy link
Author

do-web commented Sep 21, 2018

This is working now: tmp.tmpNameSync({ dir: app.getPath('temp') })

@raszi
Copy link
Owner

raszi commented Sep 22, 2018

Could you please provide the requested information, so we could make sure that tmp works in electron on your Windows platform too? Thank you!

@silkentrance
Copy link
Collaborator

@raszi I believe that tmp should fail early whenever it encounters an undefined tmpdir. What do you think?

@raszi
Copy link
Owner

raszi commented Oct 8, 2018

@silkentrance I believe that is a good idea!

silkentrance added a commit that referenced this issue Mar 13, 2019
silkentrance added a commit that referenced this issue Mar 19, 2019
silkentrance added a commit that referenced this issue Mar 20, 2019
fix: fail early if there is no tmp dir specified
@silkentrance
Copy link
Collaborator

silkentrance commented Feb 6, 2020

This was never fixed, at least not correctly.

It will also break with the changes for #207 and the way that the dir option is being treated, which can no longer be an absolute path outside of the system's default.

The correct behaviour should be for _getTmpDir() to throw an exception if the os.tmpDir() cannot be resolved as a path using path.resolve().

From the official electron docs https://www.electronjs.org/docs/all

Avoid platform-dependent code:

Use path.join() to concatenate filenames.
Use os.tmpdir() rather than /tmp when you need to reference the temporary directory.

So os.tmpdir() should be set and working around using app.getPath('temp') must not be used.

@silkentrance silkentrance reopened this Feb 6, 2020
This was referenced Feb 6, 2020
silkentrance added a commit that referenced this issue Feb 7, 2020
silkentrance added a commit that referenced this issue Feb 7, 2020
silkentrance added a commit that referenced this issue Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants