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

fs.readdir(sync) inside asar does not work with withFileTypes after "fix" #24292

Closed
3 tasks done
xssc opened this issue Jun 24, 2020 · 5 comments
Closed
3 tasks done

fs.readdir(sync) inside asar does not work with withFileTypes after "fix" #24292

xssc opened this issue Jun 24, 2020 · 5 comments

Comments

@xssc
Copy link

xssc commented Jun 24, 2020

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 9.0.5
  • Operating System:
    • macOS 10.15.2

Expected Behavior

fs.readdirsync should return an array of dirents

Actual Behavior

always returns an empty array in asar after #24062

To Reproduce

call fs.readdir/sync on any dir inside an asar

@codebytere
Copy link
Member

codebytere commented Jun 25, 2020

Are you sure you're calling it correctly? I ran the following: https://gist.github.com/a19c56fece174de46486f4d4a2934dfb

and saw:
Screen Shot 2020-06-24 at 9 21 19 PM

With the following test fixture:
test.asar.zip

Which seems correct to me.

@xssc
Copy link
Author

xssc commented Jun 25, 2020

Strange, it works fine with the asars you sent, however it does not work with any asar I make myself, I tried asar versions 2 & 3 and both simply log empty array when adding withFileTypes, where as without withFileTypes, it logs the correct array of names in the dir

@codebytere
Copy link
Member

@xssc would you be willing to send an example of a fixture that fails for you? I of course want to make it work for you/others but it's hard if i can't repro it over here 😅

@codebytere
Copy link
Member

Closing this out as it appears to work - i'll reopen should more info come to light.

@Kajot-dev
Copy link

@codebytere I have the same problem - with archive created by electron-forge (I tried re-packing it with asar3 too)
things like withe-space, underscores etc. seem to not affect the final result
I modified your main.js file (from gist in this issue):

Are you sure you're calling it correctly? I ran the following: https://gist.github.com/a19c56fece174de46486f4d4a2934dfb

  console.log("KJ's test (test_app.asar/data/html_assets)")
  const p = path.join(__dirname, "test_app.asar", "data/html_assets");
  const dirs = fs.readdirSync(p, { withFileTypes: true });
  const entries = fs.readdirSync(p);
  console.log("With file types:", dirs);
  console.log("Without file types:", entries);
  console.log("codebytere's test (a.asar/dir1)")
  const p1 = path.join(__dirname, 'test.asar', 'a.asar', 'dir1');
  const dirs1 = fs.readdirSync(p1, { withFileTypes: true });
  console.log("With file types:", dirs1)

and received the following:

KJ's test (test_app.asar/data/html_assets)
With file types: []
Without file types: [
  'block_data',
  'dialog-scripts',
  'dialogs',
  'fatal_error.html',
  'html_panels',
  'icons',
  'logo-canvas.mjs',
  'main'
]
codebytere's test (a.asar/dir1)
With file types: [
  Dirent { name: 'file1', [Symbol(type)]: 1 },
  Dirent { name: 'file2', [Symbol(type)]: 1 },
  Dirent { name: 'file3', [Symbol(type)]: 1 },
  Dirent { name: 'link1', [Symbol(type)]: 3 },
  Dirent { name: 'link2', [Symbol(type)]: 3 }
]

Tested archive (test_app.asar - mine, zipped)
test_app.zip

  • Electron version: 9.1.0
  • OS: Windows 10 2004
    Thanks in advance!

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

No branches or pull requests

3 participants