Skip to content

cannot start from a readonly path #1184

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

Closed
FrancYescO opened this issue May 3, 2024 · 2 comments
Closed

cannot start from a readonly path #1184

FrancYescO opened this issue May 3, 2024 · 2 comments

Comments

@FrancYescO
Copy link

i'm trying to embed a typeorm app with sqlite db in an ISO:

Basically the conf is:

export const dataSourceOptions: DataSourceOptions = {
  name: 'DB',
  type: 'better-sqlite3',
  database: 'db.db',
  migrationsRun: false,
  logging: true,
  synchronize: false,
  readonly: true
};

when running locally, or setting an absolute path like database: 'C:\aaaa\db.db' all is working, while running from a mounted iso, so D: is readonly and database in D:\db.db , i'm getting:
Error: EPERM: operation not permitted, mkdir 'D:\'

just for reference in these issue similar issues are getting managed
#628
#640

maybe the issue is "just" this line that is trying to check if the folder exists
https://github.com/WiseLibs/better-sqlite3/blob/master/lib/database.js#L64

@mceachen
Copy link
Member

mceachen commented May 3, 2024

I was unable to reproduce this on Windows 11 on a forced-read-only drive:

  1. Mount USB disk to D:\
const bs = require("better-sqlite3");
const db = bs("D:\\test.sqlite3");
db.exec("create table t (id INTEGER)");
db.prepare("insert into t(id) values (1),(2),(3)").run();
db.close();
  1. Unmount USB disk
  2. Enable write protection:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies]
"WriteProtect"=dword:00000001
  1. Remount disk. Verify the drive is read-only by attempting to delete or rename D:\test.sqlite3.
const bs = require("better-sqlite3");
const db = bs("D:\\test.sqlite3");
db.prepare("select * from t").all();
[ { id: 1 }, { id: 2 }, { id: 3 } ]

(if you do this to verify, undo the write protection by setting 00000001 to 00000000).

maybe the issue is "just" this line that is trying to check if the folder exists
https://github.com/WiseLibs/better-sqlite3/blob/master/lib/database.js#L64

You're getting an EPERM from mkdir. The line you referenced only checks for the existence of the directory using stat--it's not doing a mkdir.

Please open an issue on your ORM, or just run your code in your debugger and trap the exception--it should point you right at the codepath you're fighting.

@mceachen mceachen closed this as completed May 3, 2024
@FrancYescO
Copy link
Author

Thanks for the hint, i'll try to give a more consistent test case... in the meantime i've also found this node issue that seems related nodejs/node#38347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants