提交 4855cf06 编写于 作者: J Johannes Rieken

add id to FileStat and remove resource, make readdir return tuples, sketch up...

add id to FileStat and remove resource, make readdir return tuples, sketch up error codes, add todos on the API
上级 0c29dc72
......@@ -166,7 +166,7 @@ export enum FileType {
Symlink = 2
}
export interface IStat {
resource: URI;
id: number | string;
mtime: number;
size: number;
type: FileType;
......@@ -185,7 +185,7 @@ export interface IFileSystemProvider {
unlink(resource: URI): TPromise<void>;
rename(resource: URI, target: URI): TPromise<void>;
mkdir(resource: URI): TPromise<void>;
readdir(resource: URI): TPromise<IStat[]>;
readdir(resource: URI): TPromise<[URI, IStat][]>;
rmdir(resource: URI): TPromise<void>;
}
......
......@@ -120,6 +120,58 @@ declare module 'vscode' {
ignoreFocusOut?: boolean;
}
// export enum FileErrorCodes {
// /**
// * Not owner.
// */
// EPERM = 1,
// /**
// * No such file or directory.
// */
// ENOENT = 2,
// /**
// * I/O error.
// */
// EIO = 5,
// /**
// * Permission denied.
// */
// EACCES = 13,
// /**
// * File exists.
// */
// EEXIST = 17,
// /**
// * Not a directory.
// */
// ENOTDIR = 20,
// /**
// * Is a directory.
// */
// EISDIR = 21,
// /**
// * File too large.
// */
// EFBIG = 27,
// /**
// * No space left on device.
// */
// ENOSPC = 28,
// /**
// * Directory is not empty.
// */
// ENOTEMPTY = 66,
// /**
// * Invalid file handle.
// */
// ESTALE = 70,
// /**
// * Illegal NFS file handle.
// */
// EBADHANDLE = 10001,
// }
export enum FileChangeType {
Updated = 0,
Added = 1,
......@@ -138,7 +190,7 @@ declare module 'vscode' {
}
export interface FileStat {
resource: Uri;
id: number | string;
mtime: number;
size: number;
type: FileType;
......@@ -155,13 +207,40 @@ declare module 'vscode' {
//
utimes(resource: Uri, mtime: number): Thenable<FileStat>;
stat(resource: Uri): Thenable<FileStat>;
// todo@remote
// offset - byte offset to start
// count - number of bytes to read
// Thenable<number> - number of bytes actually red
read(resource: Uri, progress: Progress<Uint8Array>): Thenable<void>;
// todo@remote
// offset - byte offset to start
// count - number of bytes to write
// Thenable<number> - number of bytes actually written
write(resource: Uri, content: Uint8Array): Thenable<void>;
unlink(resource: Uri): Thenable<void>;
// todo@remote
// Thenable<FileStat>
rename(resource: Uri, target: Uri): Thenable<void>;
// todo@remote
// Thenable<FileStat>
mkdir(resource: Uri): Thenable<void>;
readdir(resource: Uri): Thenable<FileStat[]>;
readdir(resource: Uri): Thenable<[Uri, FileStat][]>;
// todo@remote
// ? merge both
// ? recursive del
rmdir(resource: Uri): Thenable<void>;
unlink(resource: Uri): Thenable<void>;
// todo@remote
// create(resource: Uri): Thenable<FileStat>;
// todo@remote
// helps with performance bigly
// copy(from: Uri, to: Uri): Thenable<void>;
}
export namespace workspace {
......
......@@ -109,7 +109,7 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
mkdir(resource: URI): TPromise<void, any> {
return this._proxy.$mkdir(this._handle, resource);
}
readdir(resource: URI): TPromise<IStat[], any> {
readdir(resource: URI): TPromise<[URI, IStat][], any> {
return this._proxy.$readdir(this._handle, resource);
}
rmdir(resource: URI): TPromise<void, any> {
......
......@@ -486,7 +486,7 @@ export interface ExtHostFileSystemShape {
$unlink(handle: number, resource: URI): TPromise<void>;
$rename(handle: number, resource: URI, target: URI): TPromise<void>;
$mkdir(handle: number, resource: URI): TPromise<void>;
$readdir(handle: number, resource: URI): TPromise<IStat[]>;
$readdir(handle: number, resource: URI): TPromise<[URI, IStat][]>;
$rmdir(handle: number, resource: URI): TPromise<void>;
}
......
......@@ -66,7 +66,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$mkdir(handle: number, resource: URI): TPromise<void, any> {
return TPromise.as<any>(this._provider.get(handle).mkdir(resource));
}
$readdir(handle: number, resource: URI): TPromise<IStat[], any> {
$readdir(handle: number, resource: URI): TPromise<[URI, IStat][], any> {
return TPromise.as<any>(this._provider.get(handle).readdir(resource));
}
$rmdir(handle: number, resource: URI): TPromise<void, any> {
......
......@@ -25,12 +25,13 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
function toIFileStat(provider: IFileSystemProvider, stat: IStat, recurse?: (stat: IStat) => boolean): TPromise<IFileStat> {
const ret: IFileStat = {
function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse?: (tuple: [URI, IStat]) => boolean): TPromise<IFileStat> {
const [resource, stat] = tuple;
const fileStat: IFileStat = {
isDirectory: false,
hasChildren: false,
resource: stat.resource,
name: basename(stat.resource.path),
resource: resource,
name: basename(resource.path),
mtime: stat.mtime,
size: stat.size,
etag: stat.mtime.toString(29) + stat.size.toString(31),
......@@ -38,38 +39,38 @@ function toIFileStat(provider: IFileSystemProvider, stat: IStat, recurse?: (stat
if (stat.type === FileType.File) {
// done
return TPromise.as(ret);
return TPromise.as(fileStat);
} else {
// dir -> resolve
return provider.readdir(stat.resource).then(items => {
ret.isDirectory = true;
ret.hasChildren = items.length > 0;
return provider.readdir(resource).then(entries => {
fileStat.isDirectory = true;
fileStat.hasChildren = entries.length > 0;
if (recurse && recurse(stat)) {
if (recurse && recurse([resource, stat])) {
// resolve children if requested
return TPromise.join(items.map(stat => toIFileStat(provider, stat, recurse))).then(children => {
ret.children = children;
return ret;
return TPromise.join(entries.map(stat => toIFileStat(provider, stat, recurse))).then(children => {
fileStat.children = children;
return fileStat;
});
} else {
return ret;
return fileStat;
}
});
}
}
export function toDeepIFileStat(provider: IFileSystemProvider, stat: IStat, to: URI[]): TPromise<IFileStat> {
export function toDeepIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], to: URI[]): TPromise<IFileStat> {
const trie = new StringTrieMap<true>();
trie.insert(stat.resource.toString(), true);
trie.insert(tuple[0].toString(), true);
if (!isFalsyOrEmpty(to)) {
to.forEach(uri => trie.insert(uri.toString(), true));
}
return toIFileStat(provider, stat, candidate => {
const sub = trie.findSuperstr(candidate.resource.toString());
return toIFileStat(provider, tuple, candidate => {
const sub = trie.findSuperstr(candidate[0].toString());
return !!sub;
});
}
......@@ -193,7 +194,7 @@ export class RemoteFileService extends FileService {
let promises: TPromise<any>[] = [];
for (const item of toResolve) {
promises.push(provider.stat(item.resource)
.then(stat => toDeepIFileStat(provider, stat, item.options && item.options.resolveTo))
.then(stat => toDeepIFileStat(provider, [item.resource, stat], item.options && item.options.resolveTo))
.then(stat => result.push({ stat, success: true })));
}
return TPromise.join(promises).then(() => result);
......@@ -221,7 +222,7 @@ export class RemoteFileService extends FileService {
private async _doResolveContent(provider: IFileSystemProvider, resource: URI): TPromise<IStreamContent> {
const stat = await toIFileStat(provider, await provider.stat(resource));
const stat = await toIFileStat(provider, [resource, await provider.stat(resource)]);
const encoding = this.getEncoding(resource);
const stream = decodeStream(encoding);
......@@ -267,7 +268,7 @@ export class RemoteFileService extends FileService {
const encoding = this.getEncoding(resource, options.encoding);
await provider.write(resource, encode(content, encoding));
const stat = await provider.stat(resource);
const fileStat = await toIFileStat(provider, stat);
const fileStat = await toIFileStat(provider, [resource, stat]);
return fileStat;
}
......@@ -306,7 +307,7 @@ export class RemoteFileService extends FileService {
} else {
const provider = await this._withProvider(resource);
await provider.mkdir(resource);
const stat = await toIFileStat(provider, await provider.stat(resource));
const stat = await toIFileStat(provider, [resource, await provider.stat(resource)]);
this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.CREATE, stat));
return stat;
}
......@@ -414,7 +415,7 @@ export class RemoteFileService extends FileService {
await provider.write(resource, new Uint8Array(0));
stat = await provider.stat(resource);
}
return toIFileStat(provider, stat);
return toIFileStat(provider, [resource, stat]);
}
// TODO@Joh - file watching on demand!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册