提交 7b6901d4 编写于 作者: B Benjamin Pasero

file - make sure to check if file is write protected again after running chmod

上级 55623887
......@@ -174,7 +174,7 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi
let errorMessage: string;
if (isReadonly) {
errorMessage = nls.localize('readonlySaveError', "Failed to save '{0}': File is write protected. Select 'Overwrite' to remove protection.", paths.basename(resource.fsPath));
errorMessage = nls.localize('readonlySaveError', "Failed to save '{0}': File is write protected. Select 'Overwrite' to attempt to remove protection.", paths.basename(resource.fsPath));
} else {
errorMessage = nls.localize('genericSaveError', "Failed to save '{0}': {1}", paths.basename(resource.fsPath), toErrorMessage(error, false));
}
......
......@@ -918,21 +918,26 @@ export class FileService implements IFileService {
}
}
let mode = stat.mode;
const readonly = !(mode & 128);
// Throw if file is readonly and we are not instructed to overwrite
if (readonly && !options.overwriteReadonly) {
return TPromise.wrapError<boolean>(new FileOperationError(
nls.localize('fileReadOnlyError', "File is Read Only"),
FileOperationResult.FILE_READ_ONLY
));
}
if (!(stat.mode & 128) /* readonly */) {
if (!options.overwriteReadonly) {
return this.readOnlyError<boolean>();
}
if (readonly) {
// Try to change mode to writeable
let mode = stat.mode;
mode = mode | 128;
return pfs.chmod(absolutePath, mode).then(() => {
// Make sure to check the mode again, it could have failed
return pfs.stat(absolutePath).then(stat => {
if (!(stat.mode & 128) /* readonly */) {
return this.readOnlyError<boolean>();
}
return pfs.chmod(absolutePath, mode).then(() => exists);
return exists;
});
});
}
return TPromise.as<boolean>(exists);
......@@ -943,6 +948,13 @@ export class FileService implements IFileService {
});
}
private readOnlyError<T>(): TPromise<T> {
return TPromise.wrapError<T>(new FileOperationError(
nls.localize('fileReadOnlyError', "File is Read Only"),
FileOperationResult.FILE_READ_ONLY
));
}
public watchFileChanges(resource: uri): void {
assert.ok(resource && resource.scheme === 'file', `Invalid resource for watching: ${resource}`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册