@@ -24,13 +24,17 @@ import type {
24
24
*/
25
25
export class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implements IFileSystemDirectoryHandle {
26
26
protected readonly ctx : Partial < NodeFsaContext > ;
27
+ /** Directory path with trailing slash. */
28
+ public readonly __path : string ;
29
+
27
30
public constructor (
28
31
protected readonly fs : NodeFsaFs ,
29
- public readonly __path : string ,
32
+ path : string ,
30
33
ctx : Partial < NodeFsaContext > = { } ,
31
34
) {
32
- super ( 'directory' , basename ( __path , ctx . separator || '/' ) ) ;
35
+ super ( 'directory' , basename ( path , ctx . separator || '/' ) ) ;
33
36
this . ctx = createCtx ( ctx ) ;
37
+ this . __path = path [ path . length - 1 ] === this . ctx . separator ? path : path + this . ctx . separator ;
34
38
}
35
39
36
40
/**
@@ -84,7 +88,7 @@ export class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implemen
84
88
options ?: GetDirectoryHandleOptions ,
85
89
) : Promise < IFileSystemDirectoryHandle > {
86
90
assertName ( name , 'getDirectoryHandle' , 'FileSystemDirectoryHandle' ) ;
87
- const filename = this . __path + this . ctx . separator ! + name ;
91
+ const filename = this . __path + name ;
88
92
try {
89
93
const stats = await this . fs . promises . stat ( filename ) ;
90
94
if ( ! stats . isDirectory ( ) ) throw newTypeMismatchError ( ) ;
@@ -121,7 +125,7 @@ export class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implemen
121
125
*/
122
126
public async getFileHandle ( name : string , options ?: GetFileHandleOptions ) : Promise < IFileSystemFileHandle > {
123
127
assertName ( name , 'getFileHandle' , 'FileSystemDirectoryHandle' ) ;
124
- const filename = this . __path + this . ctx . separator ! + name ;
128
+ const filename = this . __path + name ;
125
129
try {
126
130
const stats = await this . fs . promises . stat ( filename ) ;
127
131
if ( ! stats . isFile ( ) ) throw newTypeMismatchError ( ) ;
@@ -159,7 +163,7 @@ export class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implemen
159
163
public async removeEntry ( name : string , { recursive = false } : RemoveEntryOptions = { } ) : Promise < void > {
160
164
assertCanWrite ( this . ctx . mode ! ) ;
161
165
assertName ( name , 'removeEntry' , 'FileSystemDirectoryHandle' ) ;
162
- const filename = this . __path + this . ctx . separator ! + name ;
166
+ const filename = this . __path + name ;
163
167
const promises = this . fs . promises ;
164
168
try {
165
169
const stats = await promises . stat ( filename ) ;
0 commit comments