Skip to content

Commit 7784440

Browse files
committed
add check if root is formatted
1 parent eaf9bd7 commit 7784440

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/s3.ts

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
GetObjectCommand,
88
PutObjectCommand,
99
HeadObjectCommand,
10-
// HeadObjectCommandOutput,
1110
S3Client
1211
} from '@aws-sdk/client-s3';
1312

@@ -358,7 +357,6 @@ export const checkS3Object = async (
358357
root: string,
359358
path?: string
360359
): Promise<void> => {
361-
console.log(path, root);
362360
// checking the existance of an S3 object
363361
if (path) {
364362
await s3Client.send(

src/s3contents.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ export class Drive implements Contents.IDrive {
6060
this._region = region!;
6161
});
6262
}
63-
this.formatRoot(root ?? '').then((root: string) => {
64-
this._root = root;
65-
});
63+
this._root = root;
6664
this._registeredFileTypes = {};
6765
}
6866

@@ -130,6 +128,20 @@ export class Drive implements Contents.IDrive {
130128
this.formatRoot(root ?? '').then(root => (this._root = root));
131129
}
132130

131+
/**
132+
* Get the formatted root checker.
133+
*/
134+
get isRootFormatted(): boolean {
135+
return this._isRootFormatted;
136+
}
137+
138+
/**
139+
* Set the formatted root checker.
140+
*/
141+
set isRootFormatted(isRootFormatted) {
142+
this._isRootFormatted = isRootFormatted;
143+
}
144+
133145
/**
134146
* The Drive provider getter
135147
*/
@@ -257,6 +269,14 @@ export class Drive implements Contents.IDrive {
257269
): Promise<Contents.IModel> {
258270
path = path.replace(this._name + '/', '');
259271

272+
// format root the first time this gets called
273+
if (!this._isRootFormatted) {
274+
this.formatRoot(this._root ?? '').then((root: string) => {
275+
this._root = root;
276+
});
277+
this._isRootFormatted = true;
278+
}
279+
260280
// getting the list of files from the root
261281
if (!path) {
262282
data = await listS3Contents(
@@ -779,6 +799,7 @@ export class Drive implements Contents.IDrive {
779799
private _s3Client: S3Client;
780800
private _name: string = '';
781801
private _root: string = '';
802+
private _isRootFormatted: boolean = false;
782803
private _provider: string = '';
783804
private _baseUrl: string = '';
784805
private _region: string = '';

0 commit comments

Comments
 (0)