Merge from vscode 966b87dd4013be1a9c06e2b8334522ec61905cc2 (#4696)

This commit is contained in:
Anthony Dresser
2019-03-26 11:43:38 -07:00
committed by GitHub
parent b1393ae615
commit 0d8ef9583b
268 changed files with 5947 additions and 3422 deletions

View File

@@ -290,7 +290,7 @@ export class RemoteFileService extends FileService {
options
);
}
if (fileStat.etag === options.etag) {
if (typeof options.etag === 'string' && fileStat.etag === options.etag) {
throw new FileOperationError(
localize('fileNotModifiedError', "File not modified since"),
FileOperationResult.FILE_NOT_MODIFIED_SINCE,
@@ -407,7 +407,7 @@ export class RemoteFileService extends FileService {
return new Promise((resolve, reject) => {
readable.pipe(encoder).pipe(target);
target.once('error', err => reject(err));
target.once('finish', _ => resolve(undefined));
target.once('finish', (_: unknown) => resolve(undefined));
}).then(_ => {
return this.resolveFile(resource, { resolveMetadata: true }) as Promise<IFileStatWithMetadata>;
});
@@ -431,77 +431,6 @@ export class RemoteFileService extends FileService {
});
}
// --- delete
del(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
if (resource.scheme === Schemas.file) {
return super.del(resource, options);
} else {
return this._withProvider(resource).then(RemoteFileService._throwIfFileSystemIsReadonly).then(provider => {
return provider.delete(resource, { recursive: !!(options && options.recursive) }).then(() => {
this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.DELETE));
});
});
}
}
copyFile(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata> {
if (source.scheme === target.scheme && source.scheme === Schemas.file) {
return super.copyFile(source, target, overwrite);
}
return this._withProvider(target).then(RemoteFileService._throwIfFileSystemIsReadonly).then(provider => {
if (source.scheme === target.scheme && (provider.capabilities & FileSystemProviderCapabilities.FileFolderCopy)) {
// good: provider supports copy withing scheme
return provider.copy!(source, target, { overwrite: !!overwrite }).then(() => {
return this.resolveFile(target, { resolveMetadata: true });
}).then(fileStat => {
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
return fileStat;
}, err => {
const result = toFileOperationResult(err);
if (result === FileOperationResult.FILE_MOVE_CONFLICT) {
throw new FileOperationError(localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), result);
}
throw err;
});
}
const prepare = overwrite
? Promise.resolve(this.del(target, { recursive: true }).catch(_err => { /*ignore*/ }))
: Promise.resolve();
// todo@ben, can only copy text files
// https://github.com/Microsoft/vscode/issues/41543
return prepare.then(() => {
return this.resolveContent(source, { acceptTextOnly: true }).then(content => {
return this._withProvider(target).then(provider => {
return this._writeFile(
provider, target,
new StringSnapshot(content.value),
content.encoding,
{ create: true, overwrite: !!overwrite }
).then(fileStat => {
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
return fileStat;
});
}, err => {
const result = toFileOperationResult(err);
if (result === FileOperationResult.FILE_MOVE_CONFLICT) {
throw new FileOperationError(localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), result);
} else if (err instanceof Error && err.name === 'ENOPRO') {
// file scheme
return super.updateContent(target, content.value, { encoding: content.encoding });
} else {
return Promise.reject(err);
}
});
});
});
});
}
private _activeWatches = new Map<string, { unwatch: Promise<IDisposable>, count: number }>();
watchFileChanges(resource: URI, opts: IWatchOptions = { recursive: false, excludes: [] }): void {