@@ -18,6 +18,7 @@ import {
1818 PersistentStorageFileInfo
1919} from './PersistentStorageFactory.js'
2020import { OceanNode } from '../../OceanNode.js'
21+ import { CORE_LOGGER } from '../../utils/logging/common.js'
2122
2223export class PersistentStorageLocalFS extends PersistentStorageFactory {
2324 /* eslint-disable security/detect-non-literal-fs-filename -- localfs backend operates on filesystem paths */
@@ -29,7 +30,26 @@ export class PersistentStorageLocalFS extends PersistentStorageFactory {
2930 . options as PersistentStorageLocalFSOptions
3031
3132 this . baseFolder = options . folder
32- fsp . mkdir ( this . baseFolder , { recursive : true } )
33+
34+ // Ensure base folder exists and is a directory (sync to avoid startup races).
35+ try {
36+ fs . mkdirSync ( this . baseFolder , { recursive : true } )
37+ const st = fs . statSync ( this . baseFolder )
38+ if ( ! st . isDirectory ( ) ) {
39+ throw new Error (
40+ `Persistent storage folder is not a directory: ${ this . baseFolder } `
41+ )
42+ }
43+ fs . mkdirSync ( path . join ( this . baseFolder , 'buckets' ) , { recursive : true } )
44+ } catch ( e : any ) {
45+ if ( e ?. code === 'EACCES' ) {
46+ throw new Error (
47+ `Persistent storage folder is not accessible (EACCES): ${ this . baseFolder } . ` +
48+ `Configure 'persistentStorage.options.folder' to a writable path inside the container and mount it as a volume.`
49+ )
50+ }
51+ throw e
52+ }
3353 }
3454
3555 private bucketPath ( bucketId : string ) : string {
@@ -78,7 +98,9 @@ export class PersistentStorageLocalFS extends PersistentStorageFactory {
7898 ) : Promise < CreateBucketResult > {
7999 const bucketId = randomUUID ( )
80100 const createdAt = Math . floor ( Date . now ( ) / 1000 )
81- await fsp . mkdir ( this . bucketPath ( bucketId ) , { recursive : true } )
101+ const path = this . bucketPath ( bucketId )
102+ CORE_LOGGER . debug ( `Creating ${ path } folder for new bucket` )
103+ await fsp . mkdir ( path )
82104 await super . dbUpsertBucket (
83105 bucketId ,
84106 owner ,
0 commit comments