Skip to content

Commit 2afbf96

Browse files
Factor out IFileSystemUtils.
1 parent f30fe0d commit 2afbf96

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed

src/client/common/platform/fileSystem.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { createDeferred } from '../utils/async';
1414
import { getOSType, OSType } from '../utils/platform';
1515
import {
1616
FileStat, FileType,
17-
IFileSystem, IRawFileSystem,
17+
IFileSystem, IFileSystemUtils, IRawFileSystem,
1818
TemporaryFile, WriteStream
1919
} from './types';
2020

@@ -63,10 +63,9 @@ interface IRawFSExtra {
6363
createWriteStream(dest: string): fsextra.WriteStream;
6464
}
6565

66-
// Later we will rename "FileSystem" to "FileSystemUtils" and
67-
// "RawFileSystem" to "FileSystem".
66+
// Later we will drop "FileSystem", switching usage to
67+
// "FileSystemUtils" and then rename "RawFileSystem" to "FileSystem".
6868

69-
@injectable()
7069
class RawFileSystem {
7170
constructor(
7271
private readonly nodefs: IRawFS = fs,
@@ -168,8 +167,9 @@ class RawFileSystem {
168167
}
169168
}
170169

170+
// more aliases (to cause less churn)
171171
@injectable()
172-
export class FileSystem implements IFileSystem {
172+
export class FileSystemUtils implements IFileSystemUtils {
173173
constructor(
174174
private readonly isWindows = (getOSType() === OSType.Windows),
175175
//public readonly raw: IFileSystem = {}
@@ -179,14 +179,6 @@ export class FileSystem implements IFileSystem {
179179
//****************************
180180
// aliases
181181

182-
public async readFile(filename: string): Promise<string> {
183-
return this.raw.readText(filename);
184-
}
185-
186-
public async writeFile(filename: string, data: {}): Promise<void> {
187-
return this.raw.writeText(filename, data);
188-
}
189-
190182
public async createDirectory(dirname: string): Promise<void> {
191183
return this.raw.mkdirp(dirname);
192184
}
@@ -199,22 +191,6 @@ export class FileSystem implements IFileSystem {
199191
return this.raw.rmfile(filename);
200192
}
201193

202-
public async chmod(filename: string, mode: string): Promise<void> {
203-
return this.raw.chmod(filename, mode);
204-
}
205-
206-
public async copyFile(src: string, dest: string): Promise<void> {
207-
return this.raw.copyFile(src, dest);
208-
}
209-
210-
public readFileSync(filename: string): string {
211-
return this.raw.readTextSync(filename);
212-
}
213-
214-
public createWriteStream(filename: string): WriteStream {
215-
return this.raw.createWriteStream(filename);
216-
}
217-
218194
//****************************
219195
// helpers
220196

@@ -336,3 +312,30 @@ export class FileSystem implements IFileSystem {
336312
});
337313
}
338314
}
315+
316+
@injectable()
317+
export class FileSystem extends FileSystemUtils implements IFileSystem {
318+
public async readFile(filename: string): Promise<string> {
319+
return this.raw.readText(filename);
320+
}
321+
322+
public async writeFile(filename: string, data: {}): Promise<void> {
323+
return this.raw.writeText(filename, data);
324+
}
325+
326+
public async chmod(filename: string, mode: string): Promise<void> {
327+
return this.raw.chmod(filename, mode);
328+
}
329+
330+
public async copyFile(src: string, dest: string): Promise<void> {
331+
return this.raw.copyFile(src, dest);
332+
}
333+
334+
public readFileSync(filename: string): string {
335+
return this.raw.readTextSync(filename);
336+
}
337+
338+
public createWriteStream(filename: string): WriteStream {
339+
return this.raw.createWriteStream(filename);
340+
}
341+
}

src/client/common/platform/serviceRegistry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
'use strict';
44

55
import { IServiceManager } from '../../ioc/types';
6-
import { FileSystem } from './fileSystem';
6+
import { FileSystem, FileSystemUtils } from './fileSystem';
77
import { PlatformService } from './platformService';
88
import { RegistryImplementation } from './registry';
9-
import { IFileSystem, IPlatformService, IRegistry } from './types';
9+
import { IFileSystem, IFileSystemUtils, IPlatformService, IRegistry } from './types';
1010

1111
export function registerTypes(serviceManager: IServiceManager) {
1212
serviceManager.addSingleton<IPlatformService>(IPlatformService, PlatformService);
1313
serviceManager.addSingleton<IFileSystem>(IFileSystem, FileSystem);
14+
serviceManager.addSingleton<IFileSystemUtils>(IFileSystemUtils, FileSystemUtils);
1415
serviceManager.addSingleton<IRegistry>(IRegistry, RegistryImplementation);
1516
}

src/client/common/platform/types.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export import FileType = vscode.FileType;
4545
export type FileStat = fsextra.Stats;
4646
export type WriteStream = fs.WriteStream;
4747

48-
// Later we will rename "IFileSystem" to "IFileSystemUtils" and
49-
// "IRawFileSystem" to "IFileSystem".
48+
// Later we will drop "IFileSystem", switching usage to
49+
// "IFileSystemUtils" and then rename "IRawFileSystem" to "IFileSystem".
5050

5151
export interface IRawFileSystem {
5252
stat(filename: string): Promise<FileStat>;
@@ -68,20 +68,13 @@ export interface IRawFileSystem {
6868
createWriteStream(filename: string): WriteStream;
6969
}
7070

71-
export const IFileSystem = Symbol('IFileSystem');
72-
export interface IFileSystem {
71+
export const IFileSystemUtils = Symbol('IFileSystemUtils');
72+
export interface IFileSystemUtils {
7373
raw: IRawFileSystem;
74-
// aliases (to cause less churn)
75-
readFile(filename: string): Promise<string>;
76-
writeFile(filename: string, data: {}): Promise<void>;
74+
// aliases
7775
createDirectory(dirname: string): Promise<void>;
7876
deleteDirectory(dirname: string): Promise<void>;
7977
deleteFile(filename: string): Promise<void>;
80-
chmod(filename: string, mode: string): Promise<void>;
81-
copyFile(src: string, dest: string): Promise<void>;
82-
// aliases (non-async)
83-
readFileSync(filename: string): string;
84-
createWriteStream(filename: string): WriteStream;
8578
// helpers
8679
pathExists(filename: string, fileType?: FileType): Promise<boolean>;
8780
fileExists(filename: string): Promise<boolean>;
@@ -96,3 +89,15 @@ export interface IFileSystem {
9689
arePathsSame(path1: string, path2: string): boolean; // Move to IPathUtils.
9790
fileExistsSync(filename: string): boolean;
9891
}
92+
93+
// more aliases (to cause less churn)
94+
export const IFileSystem = Symbol('IFileSystem');
95+
export interface IFileSystem extends IFileSystemUtils {
96+
readFile(filename: string): Promise<string>;
97+
writeFile(filename: string, data: {}): Promise<void>;
98+
chmod(filename: string, mode: string): Promise<void>;
99+
copyFile(src: string, dest: string): Promise<void>;
100+
// non-async
101+
readFileSync(filename: string): string;
102+
createWriteStream(filename: string): WriteStream;
103+
}

0 commit comments

Comments
 (0)