提交 94deeec3 编写于 作者: J Johannes Rieken

properly stat files and folders

上级 cc2acee6
......@@ -12,7 +12,7 @@ import * as JSFtp from 'jsftp';
import { ninvoke } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
import { Readable } from 'stream';
import { join } from 'path';
import { join, dirname, basename } from 'path';
import { IStat, FileType, IFileSystemProvider } from 'vs/platform/files/common/files';
import { IProgress } from 'vs/platform/progress/common/progress';
......@@ -34,27 +34,32 @@ export class FtpFileSystemProvider implements IFileSystemProvider {
}
stat(resource: URI): TPromise<IStat> {
const { path } = resource;
if (path === '/') {
// root directory
return TPromise.as(<IStat>{
type: FileType.Dir,
resource,
mtime: 0,
size: 0
});
}
return ninvoke<JSFtp.Entry[]>(this._connection, this._connection.ls, resource.path).then(entries => {
if (entries.length === 1) {
// stat one file
const [entry] = entries;
const name = basename(path);
const dir = dirname(path);
return ninvoke<JSFtp.Entry[]>(this._connection, this._connection.ls, dir).then(entries => {
for (const entry of entries) {
if (entry.name === name) {
return {
resource,
mtime: entry.time,
size: entry.size,
type: FileType.File
type: entry.type
};
}
// stat directory
return <IStat>{
resource,
mtime: 0,
size: 0,
type: FileType.Dir,
};
}
console.log(entries, name, resource);
throw new Error(`NotFound: ${resource.path}`);
});
}
......
import { Readable } from 'stream';
import { EventEmitter } from 'events';
declare namespace JSFtp {
......@@ -10,6 +11,7 @@ declare namespace JSFtp {
port?: number | 21;
user?: string | 'anonymous';
pass?: string | '@anonymous';
useList?: boolean
}
interface Callback<T> {
......@@ -25,11 +27,13 @@ declare namespace JSFtp {
}
}
interface JSFtp {
interface JSFtp extends EventEmitter {
keepAlive(wait?: number): void;
ls(path: string, callback: JSFtp.Callback<JSFtp.Entry[]>): void;
list(path: string, callback: JSFtp.Callback<any>): void;
put(buffer: Buffer, path: string, callback: JSFtp.Callback<void>): void;
get(path: string, callback: JSFtp.Callback<Readable>): void;
setType(type: 'A' | 'AN' | 'AT' | 'AC' | 'E' | 'I' | 'L', callback: JSFtp.Callback<any>): void;
raw<T = any>(command: string, args: any[], callback: JSFtp.Callback<T>): void
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册