Skip to content

Commit 3863ac4

Browse files
committed
fix: StorageInstance.exists returns boolean and LocalStorage handles undefined folder
Signed-off-by: fazeel332@gmail.com <fazeel332@gmail.com>
1 parent d978e02 commit 3863ac4

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

packages/core/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class LocalStorage extends StorageConnector {
4949
private findStorageFolder(folder) {
5050
let _storageFolder = folder;
5151

52-
if (fs.existsSync(_storageFolder)) {
52+
if (_storageFolder && fs.existsSync(_storageFolder)) {
5353
return _storageFolder;
5454
}
5555

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { LocalStorage } from '@sre/IO/Storage.service/connectors/LocalStorage.class';
2+
import { describe, expect, it } from 'vitest';
3+
4+
describe('LocalStorage Tests', () => {
5+
it('should initialize with undefined folder without crashing', () => {
6+
// Test with undefined settings
7+
expect(() => {
8+
new LocalStorage();
9+
}).not.toThrow();
10+
11+
// Test with empty settings object
12+
expect(() => {
13+
new LocalStorage({});
14+
}).not.toThrow();
15+
16+
// Test with explicitly undefined folder
17+
expect(() => {
18+
new LocalStorage({ folder: undefined });
19+
}).not.toThrow();
20+
});
21+
22+
it('should initialize with valid folder path', () => {
23+
const tempDir = require('os').tmpdir();
24+
25+
expect(() => {
26+
new LocalStorage({ folder: tempDir });
27+
}).not.toThrow();
28+
});
29+
30+
it('should handle non-existent folder gracefully', () => {
31+
// This should not crash but may log warnings as designed
32+
expect(() => {
33+
new LocalStorage({ folder: '/non/existent/path/that/should/not/exist' });
34+
}).not.toThrow();
35+
});
36+
});

packages/sdk/src/Storage/StorageInstance.class.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ export class StorageInstance extends SDKObject {
119119
* @param resourceName - The name or smythfs:// uri of the resource to check
120120
* @returns true if the resource exists, false otherwise
121121
*/
122-
async exists(resourceName: string) {
122+
async exists(resourceName: string): Promise<boolean> {
123123
const uri = resourceName.startsWith('smythfs://') ? resourceName : await this.getResourceUri(resourceName);
124124
try {
125-
await this.fs.exists(uri, this._candidate);
126-
return uri;
125+
return await this.fs.exists(uri, this._candidate);
127126
} catch (error) {
128127
console.error(error);
129128
throw error;

0 commit comments

Comments
 (0)