-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
files2 - support overwrite readonly for local files
- Loading branch information
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/vs/workbench/services/textfile/node/textFileService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService'; | ||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; | ||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; | ||
import { URI } from 'vs/base/common/uri'; | ||
import { ITextSnapshot, IWriteTextFileOptions, IFileStatWithMetadata } from 'vs/platform/files/common/files'; | ||
import { Schemas } from 'vs/base/common/network'; | ||
import { exists, stat, chmod } from 'vs/base/node/pfs'; | ||
|
||
export class NodeTextFileService extends TextFileService { | ||
|
||
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> { | ||
|
||
// check for overwriteReadonly property (only supported for local file://) | ||
try { | ||
if (options && options.overwriteReadonly && resource.scheme === Schemas.file && await exists(resource.fsPath)) { | ||
const fileStat = await stat(resource.fsPath); | ||
|
||
// try to change mode to writeable | ||
await chmod(resource.fsPath, fileStat.mode | 128); | ||
} | ||
} catch (error) { | ||
// ignore and simply retry the operation | ||
} | ||
|
||
return super.write(resource, value, options); | ||
} | ||
} | ||
|
||
registerSingleton(ITextFileService, NodeTextFileService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters