@theia/filesystem 1.26.0-next.41 → 1.26.0-next.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/file-tree/file-tree-widget.js +1 -1
- package/lib/browser/file-tree/file-tree-widget.js.map +1 -1
- package/lib/browser/file-tree/file-tree.d.ts +1 -2
- package/lib/browser/file-tree/file-tree.d.ts.map +1 -1
- package/lib/browser/file-tree/file-tree.js.map +1 -1
- package/lib/browser/filesystem-frontend-module.d.ts.map +1 -1
- package/lib/browser/filesystem-frontend-module.js +0 -165
- package/lib/browser/filesystem-frontend-module.js.map +1 -1
- package/lib/browser/index.d.ts +0 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +0 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/common/files.d.ts +1 -1
- package/lib/common/filesystem-watcher-protocol.d.ts +1 -22
- package/lib/common/filesystem-watcher-protocol.d.ts.map +1 -1
- package/lib/common/filesystem-watcher-protocol.js +1 -68
- package/lib/common/filesystem-watcher-protocol.js.map +1 -1
- package/lib/common/filesystem.d.ts +0 -226
- package/lib/common/filesystem.d.ts.map +1 -1
- package/lib/common/filesystem.js +1 -48
- package/lib/common/filesystem.js.map +1 -1
- package/lib/common/remote-file-system-provider.d.ts +9 -9
- package/lib/common/remote-file-system-provider.d.ts.map +1 -1
- package/lib/common/remote-file-system-provider.js +10 -9
- package/lib/common/remote-file-system-provider.js.map +1 -1
- package/package.json +3 -3
- package/src/browser/file-tree/file-tree-widget.tsx +1 -1
- package/src/browser/file-tree/file-tree.ts +1 -2
- package/src/browser/filesystem-frontend-module.ts +0 -162
- package/src/browser/index.ts +0 -1
- package/src/common/files.ts +1 -1
- package/src/common/filesystem-watcher-protocol.ts +1 -67
- package/src/common/filesystem.ts +0 -259
- package/src/common/remote-file-system-provider.ts +19 -18
- package/lib/browser/filesystem-watcher.d.ts +0 -134
- package/lib/browser/filesystem-watcher.d.ts.map +0 -1
- package/lib/browser/filesystem-watcher.js +0 -240
- package/lib/browser/filesystem-watcher.js.map +0 -1
- package/lib/node/node-file-upload.d.ts +0 -19
- package/lib/node/node-file-upload.d.ts.map +0 -1
- package/lib/node/node-file-upload.js +0 -55
- package/lib/node/node-file-upload.js.map +0 -1
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.d.ts +0 -53
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.d.ts.map +0 -1
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.js +0 -197
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.js.map +0 -1
- package/src/browser/filesystem-watcher.ts +0 -249
- package/src/node/node-file-upload.ts +0 -64
- package/src/node/nsfw-watcher/nsfw-filesystem-watcher.ts +0 -255
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2017-2018 TypeFox and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.NsfwFileSystemWatcherServer = void 0;
|
|
19
|
-
const fs = require("fs");
|
|
20
|
-
const nsfw = require("@theia/core/shared/nsfw");
|
|
21
|
-
const paths = require("path");
|
|
22
|
-
const minimatch_1 = require("minimatch");
|
|
23
|
-
const disposable_1 = require("@theia/core/lib/common/disposable");
|
|
24
|
-
const file_uri_1 = require("@theia/core/lib/node/file-uri");
|
|
25
|
-
const file_change_collection_1 = require("../file-change-collection");
|
|
26
|
-
const timers_1 = require("timers");
|
|
27
|
-
const debounce = require("@theia/core/shared/lodash.debounce");
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated since 1.6.0 use `NsfwFileSystemWatcherService` instead.
|
|
30
|
-
*/
|
|
31
|
-
class NsfwFileSystemWatcherServer {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
this.watcherSequence = 1;
|
|
34
|
-
this.watchers = new Map();
|
|
35
|
-
this.watcherOptions = new Map();
|
|
36
|
-
this.toDispose = new disposable_1.DisposableCollection(disposable_1.Disposable.create(() => this.setClient(undefined)));
|
|
37
|
-
this.changes = new file_change_collection_1.FileChangeCollection();
|
|
38
|
-
/**
|
|
39
|
-
* Fires file changes to clients.
|
|
40
|
-
* It is debounced in the case if the filesystem is spamming to avoid overwhelming clients with events.
|
|
41
|
-
*/
|
|
42
|
-
this.fireDidFilesChanged = debounce(() => this.doFireDidFilesChanged(), 50);
|
|
43
|
-
this.options = Object.assign({ nsfwOptions: {}, verbose: false, info: (message, ...args) => console.info(message, ...args), error: (message, ...args) => console.error(message, ...args) }, options);
|
|
44
|
-
}
|
|
45
|
-
dispose() {
|
|
46
|
-
this.toDispose.dispose();
|
|
47
|
-
}
|
|
48
|
-
async watchFileChanges(uri, options) {
|
|
49
|
-
const watcherId = this.watcherSequence++;
|
|
50
|
-
const basePath = file_uri_1.FileUri.fsPath(uri);
|
|
51
|
-
this.debug('Starting watching:', basePath);
|
|
52
|
-
const toDisposeWatcher = new disposable_1.DisposableCollection();
|
|
53
|
-
this.watchers.set(watcherId, toDisposeWatcher);
|
|
54
|
-
toDisposeWatcher.push(disposable_1.Disposable.create(() => this.watchers.delete(watcherId)));
|
|
55
|
-
if (fs.existsSync(basePath)) {
|
|
56
|
-
this.start(watcherId, basePath, options, toDisposeWatcher);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const toClearTimer = new disposable_1.DisposableCollection();
|
|
60
|
-
const timer = (0, timers_1.setInterval)(() => {
|
|
61
|
-
if (fs.existsSync(basePath)) {
|
|
62
|
-
toClearTimer.dispose();
|
|
63
|
-
this.pushAdded(watcherId, basePath);
|
|
64
|
-
this.start(watcherId, basePath, options, toDisposeWatcher);
|
|
65
|
-
}
|
|
66
|
-
}, 500);
|
|
67
|
-
toClearTimer.push(disposable_1.Disposable.create(() => (0, timers_1.clearInterval)(timer)));
|
|
68
|
-
toDisposeWatcher.push(toClearTimer);
|
|
69
|
-
}
|
|
70
|
-
this.toDispose.push(toDisposeWatcher);
|
|
71
|
-
return watcherId;
|
|
72
|
-
}
|
|
73
|
-
async start(watcherId, basePath, rawOptions, toDisposeWatcher) {
|
|
74
|
-
const options = Object.assign({ ignored: [] }, rawOptions);
|
|
75
|
-
if (options.ignored.length > 0) {
|
|
76
|
-
this.debug('Files ignored for watching', options.ignored);
|
|
77
|
-
}
|
|
78
|
-
let watcher = await nsfw(fs.realpathSync(basePath), (events) => {
|
|
79
|
-
for (const event of events) {
|
|
80
|
-
if (event.action === 0 /* CREATED */) {
|
|
81
|
-
this.pushAdded(watcherId, this.resolvePath(event.directory, event.file));
|
|
82
|
-
}
|
|
83
|
-
if (event.action === 1 /* DELETED */) {
|
|
84
|
-
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file));
|
|
85
|
-
}
|
|
86
|
-
if (event.action === 2 /* MODIFIED */) {
|
|
87
|
-
this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file));
|
|
88
|
-
}
|
|
89
|
-
if (event.action === 3 /* RENAMED */) {
|
|
90
|
-
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile));
|
|
91
|
-
this.pushAdded(watcherId, this.resolvePath(event.newDirectory || event.directory, event.newFile));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}, Object.assign({ errorCallback: error => {
|
|
95
|
-
// see https://github.com/atom/github/issues/342
|
|
96
|
-
console.warn(`Failed to watch "${basePath}":`, error);
|
|
97
|
-
if (error === 'Inotify limit reached') {
|
|
98
|
-
if (this.client) {
|
|
99
|
-
this.client.onError();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
this.unwatchFileChanges(watcherId);
|
|
103
|
-
} }, this.options.nsfwOptions));
|
|
104
|
-
await watcher.start();
|
|
105
|
-
this.options.info('Started watching:', basePath);
|
|
106
|
-
if (toDisposeWatcher.disposed) {
|
|
107
|
-
this.debug('Stopping watching:', basePath);
|
|
108
|
-
await watcher.stop();
|
|
109
|
-
// remove a reference to nsfw otherwise GC cannot collect it
|
|
110
|
-
watcher = undefined;
|
|
111
|
-
this.options.info('Stopped watching:', basePath);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
toDisposeWatcher.push(disposable_1.Disposable.create(async () => {
|
|
115
|
-
this.watcherOptions.delete(watcherId);
|
|
116
|
-
if (watcher) {
|
|
117
|
-
this.debug('Stopping watching:', basePath);
|
|
118
|
-
await watcher.stop();
|
|
119
|
-
// remove a reference to nsfw otherwise GC cannot collect it
|
|
120
|
-
watcher = undefined;
|
|
121
|
-
this.options.info('Stopped watching:', basePath);
|
|
122
|
-
}
|
|
123
|
-
}));
|
|
124
|
-
this.watcherOptions.set(watcherId, {
|
|
125
|
-
ignored: options.ignored.map(pattern => new minimatch_1.Minimatch(pattern, { dot: true }))
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
unwatchFileChanges(watcherId) {
|
|
129
|
-
const disposable = this.watchers.get(watcherId);
|
|
130
|
-
if (disposable) {
|
|
131
|
-
this.watchers.delete(watcherId);
|
|
132
|
-
disposable.dispose();
|
|
133
|
-
}
|
|
134
|
-
return Promise.resolve();
|
|
135
|
-
}
|
|
136
|
-
setClient(client) {
|
|
137
|
-
if (client && this.toDispose.disposed) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.client = client;
|
|
141
|
-
}
|
|
142
|
-
pushAdded(watcherId, path) {
|
|
143
|
-
this.debug('Added:', path);
|
|
144
|
-
this.pushFileChange(watcherId, path, 1 /* ADDED */);
|
|
145
|
-
}
|
|
146
|
-
pushUpdated(watcherId, path) {
|
|
147
|
-
this.debug('Updated:', path);
|
|
148
|
-
this.pushFileChange(watcherId, path, 0 /* UPDATED */);
|
|
149
|
-
}
|
|
150
|
-
pushDeleted(watcherId, path) {
|
|
151
|
-
this.debug('Deleted:', path);
|
|
152
|
-
this.pushFileChange(watcherId, path, 2 /* DELETED */);
|
|
153
|
-
}
|
|
154
|
-
pushFileChange(watcherId, path, type) {
|
|
155
|
-
if (this.isIgnored(watcherId, path)) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const uri = file_uri_1.FileUri.create(path).toString();
|
|
159
|
-
this.changes.push({ uri, type });
|
|
160
|
-
this.fireDidFilesChanged();
|
|
161
|
-
}
|
|
162
|
-
resolvePath(directory, file) {
|
|
163
|
-
const path = paths.join(directory, file);
|
|
164
|
-
try {
|
|
165
|
-
return fs.realpathSync(path);
|
|
166
|
-
}
|
|
167
|
-
catch (_a) {
|
|
168
|
-
try {
|
|
169
|
-
// file does not exist try to resolve directory
|
|
170
|
-
return paths.join(fs.realpathSync(directory), file);
|
|
171
|
-
}
|
|
172
|
-
catch (_b) {
|
|
173
|
-
// directory does not exist fall back to symlink
|
|
174
|
-
return path;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
doFireDidFilesChanged() {
|
|
179
|
-
const changes = this.changes.values();
|
|
180
|
-
this.changes = new file_change_collection_1.FileChangeCollection();
|
|
181
|
-
const event = { changes };
|
|
182
|
-
if (this.client) {
|
|
183
|
-
this.client.onDidFilesChanged(event);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
isIgnored(watcherId, path) {
|
|
187
|
-
const options = this.watcherOptions.get(watcherId);
|
|
188
|
-
return !!options && options.ignored.length > 0 && options.ignored.some(m => m.match(path));
|
|
189
|
-
}
|
|
190
|
-
debug(message, ...params) {
|
|
191
|
-
if (this.options.verbose) {
|
|
192
|
-
this.options.info(message, ...params);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
exports.NsfwFileSystemWatcherServer = NsfwFileSystemWatcherServer;
|
|
197
|
-
//# sourceMappingURL=nsfw-filesystem-watcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nsfw-filesystem-watcher.js","sourceRoot":"","sources":["../../../src/node/nsfw-watcher/nsfw-filesystem-watcher.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8CAA8C;AAC9C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;;AAEhF,yBAAyB;AACzB,gDAAgD;AAChD,8BAA8B;AAC9B,yCAAkD;AAClD,kEAAqF;AACrF,4DAAwD;AAOxD,sEAAiE;AACjE,mCAAoD;AAEpD,+DAAgE;AAWhE;;GAEG;AACH,MAAa,2BAA2B;IAqBpC,YAAY,OAKX;QAtBS,oBAAe,GAAG,CAAC,CAAC;QACX,aAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;QACzC,mBAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;QAEnD,cAAS,GAAG,IAAI,iCAAoB,CACnD,uBAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CACrD,CAAC;QAEQ,YAAO,GAAG,IAAI,6CAAoB,EAAE,CAAC;QA6K/C;;;WAGG;QACgB,wBAAmB,GAAe,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,EAAE,CAAC,CAAC;QAlKlG,IAAI,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C;aACvD;YAAC,WAAM;gBACJ,gDAAgD;gBAChD,OAAO,IAAI,CAAC;aACf;SACJ;IACL,CAAC;IAOS,qBAAqB;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,IAAI,6CAAoB,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,EAAE,OAAO,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;SACxC;IACL,CAAC;IAES,SAAS,CAAC,SAAiB,EAAE,IAAY;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACnD,OAAO,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/F,CAAC;IAES,KAAK,CAAC,OAAe,EAAE,GAAG,MAAa;QAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;SACzC;IACL,CAAC;CACJ;AAjND,kEAiNC"}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
19
|
-
import { Emitter, WaitUntilEvent } from '@theia/core/lib/common/event';
|
|
20
|
-
import URI from '@theia/core/lib/common/uri';
|
|
21
|
-
import { FileChangeType, FileOperation } from '../common/files';
|
|
22
|
-
import { FileService } from './file-service';
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
FileChangeType
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export interface FileChange {
|
|
29
|
-
uri: URI;
|
|
30
|
-
type: FileChangeType;
|
|
31
|
-
}
|
|
32
|
-
export namespace FileChange {
|
|
33
|
-
export function isUpdated(change: FileChange, uri: URI): boolean {
|
|
34
|
-
return change.type === FileChangeType.UPDATED && uri.toString() === change.uri.toString();
|
|
35
|
-
}
|
|
36
|
-
export function isAdded(change: FileChange, uri: URI): boolean {
|
|
37
|
-
return change.type === FileChangeType.ADDED && uri.toString() === change.uri.toString();
|
|
38
|
-
}
|
|
39
|
-
export function isDeleted(change: FileChange, uri: URI): boolean {
|
|
40
|
-
return change.type === FileChangeType.DELETED && change.uri.isEqualOrParent(uri);
|
|
41
|
-
}
|
|
42
|
-
export function isAffected(change: FileChange, uri: URI): boolean {
|
|
43
|
-
return isDeleted(change, uri) || uri.toString() === change.uri.toString();
|
|
44
|
-
}
|
|
45
|
-
export function isChanged(change: FileChange, uri: URI): boolean {
|
|
46
|
-
return !isDeleted(change, uri) && uri.toString() === change.uri.toString();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileChangesEvent` instead
|
|
52
|
-
*/
|
|
53
|
-
export type FileChangeEvent = FileChange[];
|
|
54
|
-
export namespace FileChangeEvent {
|
|
55
|
-
export function isUpdated(event: FileChangeEvent, uri: URI): boolean {
|
|
56
|
-
return event.some(change => FileChange.isUpdated(change, uri));
|
|
57
|
-
}
|
|
58
|
-
export function isAdded(event: FileChangeEvent, uri: URI): boolean {
|
|
59
|
-
return event.some(change => FileChange.isAdded(change, uri));
|
|
60
|
-
}
|
|
61
|
-
export function isDeleted(event: FileChangeEvent, uri: URI): boolean {
|
|
62
|
-
return event.some(change => FileChange.isDeleted(change, uri));
|
|
63
|
-
}
|
|
64
|
-
export function isAffected(event: FileChangeEvent, uri: URI): boolean {
|
|
65
|
-
return event.some(change => FileChange.isAffected(change, uri));
|
|
66
|
-
}
|
|
67
|
-
export function isChanged(event: FileChangeEvent, uri: URI): boolean {
|
|
68
|
-
return !isDeleted(event, uri) && event.some(change => FileChange.isChanged(change, uri));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `UserFileOperationEvent` instead
|
|
74
|
-
*/
|
|
75
|
-
export interface FileMoveEvent extends WaitUntilEvent {
|
|
76
|
-
sourceUri: URI
|
|
77
|
-
targetUri: URI
|
|
78
|
-
}
|
|
79
|
-
export namespace FileMoveEvent {
|
|
80
|
-
export function isRename({ sourceUri, targetUri }: FileMoveEvent): boolean {
|
|
81
|
-
return sourceUri.parent.toString() === targetUri.parent.toString();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `UserFileOperationEvent` instead
|
|
87
|
-
*/
|
|
88
|
-
export interface FileEvent extends WaitUntilEvent {
|
|
89
|
-
uri: URI
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class FileOperationEmitter<E extends WaitUntilEvent> implements Disposable {
|
|
93
|
-
|
|
94
|
-
protected readonly onWillEmitter = new Emitter<E>();
|
|
95
|
-
readonly onWill = this.onWillEmitter.event;
|
|
96
|
-
|
|
97
|
-
protected readonly onDidFailEmitter = new Emitter<E>();
|
|
98
|
-
readonly onDidFail = this.onDidFailEmitter.event;
|
|
99
|
-
|
|
100
|
-
protected readonly onDidEmitter = new Emitter<E>();
|
|
101
|
-
readonly onDid = this.onDidEmitter.event;
|
|
102
|
-
|
|
103
|
-
protected readonly toDispose = new DisposableCollection(
|
|
104
|
-
this.onWillEmitter,
|
|
105
|
-
this.onDidFailEmitter,
|
|
106
|
-
this.onDidEmitter
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
dispose(): void {
|
|
110
|
-
this.toDispose.dispose();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async fireWill(event: Pick<E, Exclude<keyof E, 'waitUntil'>>): Promise<void> {
|
|
114
|
-
await WaitUntilEvent.fire(this.onWillEmitter, event);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async fireDid(failed: boolean, event: Pick<E, Exclude<keyof E, 'waitUntil'>>): Promise<void> {
|
|
118
|
-
const onDidEmitter = failed ? this.onDidFailEmitter : this.onDidEmitter;
|
|
119
|
-
await WaitUntilEvent.fire(onDidEmitter, event);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* React to file system events, including calls originating from the
|
|
126
|
-
* application or event coming from the system's filesystem directly
|
|
127
|
-
* (actual file watching).
|
|
128
|
-
*
|
|
129
|
-
* `on(will|did)(create|rename|delete)` events solely come from application
|
|
130
|
-
* usage, not from actual filesystem.
|
|
131
|
-
*
|
|
132
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.watch` instead
|
|
133
|
-
*/
|
|
134
|
-
@injectable()
|
|
135
|
-
export class FileSystemWatcher implements Disposable {
|
|
136
|
-
|
|
137
|
-
protected readonly toDispose = new DisposableCollection();
|
|
138
|
-
protected readonly toRestartAll = new DisposableCollection();
|
|
139
|
-
|
|
140
|
-
protected readonly onFileChangedEmitter = new Emitter<FileChangeEvent>();
|
|
141
|
-
/**
|
|
142
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onDidFilesChange` instead
|
|
143
|
-
*/
|
|
144
|
-
readonly onFilesChanged = this.onFileChangedEmitter.event;
|
|
145
|
-
|
|
146
|
-
protected readonly fileCreateEmitter = new FileOperationEmitter<FileEvent>();
|
|
147
|
-
/**
|
|
148
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onWillRunUserOperation` instead
|
|
149
|
-
*/
|
|
150
|
-
readonly onWillCreate = this.fileCreateEmitter.onWill;
|
|
151
|
-
/**
|
|
152
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onDidFailUserOperation` instead
|
|
153
|
-
*/
|
|
154
|
-
readonly onDidFailCreate = this.fileCreateEmitter.onDidFail;
|
|
155
|
-
/**
|
|
156
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908),
|
|
157
|
-
* instead use `FileService.onDidRunUserOperation` for events triggered by user gestures
|
|
158
|
-
* or `FileService.onDidRunOperation` triggered by user gestures and programmatically
|
|
159
|
-
*/
|
|
160
|
-
readonly onDidCreate = this.fileCreateEmitter.onDid;
|
|
161
|
-
|
|
162
|
-
protected readonly fileDeleteEmitter = new FileOperationEmitter<FileEvent>();
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onWillRunUserOperation` instead
|
|
165
|
-
*/
|
|
166
|
-
readonly onWillDelete = this.fileDeleteEmitter.onWill;
|
|
167
|
-
/**
|
|
168
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onDidFailUserOperation` instead
|
|
169
|
-
*/
|
|
170
|
-
readonly onDidFailDelete = this.fileDeleteEmitter.onDidFail;
|
|
171
|
-
/**
|
|
172
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908),
|
|
173
|
-
* instead use `FileService.onDidRunUserOperation` for events triggered by user gestures
|
|
174
|
-
* or `FileService.onDidRunOperation` triggered by user gestures and programmatically
|
|
175
|
-
*/
|
|
176
|
-
readonly onDidDelete = this.fileDeleteEmitter.onDid;
|
|
177
|
-
|
|
178
|
-
protected readonly fileMoveEmitter = new FileOperationEmitter<FileMoveEvent>();
|
|
179
|
-
/**
|
|
180
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onWillRunUserOperation` instead
|
|
181
|
-
*/
|
|
182
|
-
readonly onWillMove = this.fileMoveEmitter.onWill;
|
|
183
|
-
/**
|
|
184
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908), use `FileService.onDidFailUserOperation` instead
|
|
185
|
-
*/
|
|
186
|
-
readonly onDidFailMove = this.fileMoveEmitter.onDidFail;
|
|
187
|
-
/**
|
|
188
|
-
* @deprecated since 1.4.0 - in order to support VS Code FS API (https://github.com/eclipse-theia/theia/pull/7908),
|
|
189
|
-
* instead use `FileService.onDidRunUserOperation` for events triggered by user gestures
|
|
190
|
-
* or `FileService.onDidRunOperation` triggered by user gestures and programmatically
|
|
191
|
-
*/
|
|
192
|
-
readonly onDidMove = this.fileMoveEmitter.onDid;
|
|
193
|
-
|
|
194
|
-
@inject(FileService)
|
|
195
|
-
protected readonly fileService: FileService;
|
|
196
|
-
|
|
197
|
-
@postConstruct()
|
|
198
|
-
protected init(): void {
|
|
199
|
-
this.toDispose.push(this.onFileChangedEmitter);
|
|
200
|
-
this.toDispose.push(this.fileDeleteEmitter);
|
|
201
|
-
this.toDispose.push(this.fileMoveEmitter);
|
|
202
|
-
|
|
203
|
-
this.toDispose.push(this.fileService.onWillRunUserOperation(event => {
|
|
204
|
-
if (event.operation === FileOperation.CREATE) {
|
|
205
|
-
this.fileCreateEmitter.fireWill({ uri: event.target });
|
|
206
|
-
} else if (event.operation === FileOperation.DELETE) {
|
|
207
|
-
this.fileDeleteEmitter.fireWill({ uri: event.target });
|
|
208
|
-
} else if (event.operation === FileOperation.MOVE && event.source) {
|
|
209
|
-
this.fileMoveEmitter.fireWill({ sourceUri: event.source, targetUri: event.target });
|
|
210
|
-
}
|
|
211
|
-
}));
|
|
212
|
-
this.toDispose.push(this.fileService.onDidFailUserOperation(event => {
|
|
213
|
-
if (event.operation === FileOperation.CREATE) {
|
|
214
|
-
this.fileCreateEmitter.fireDid(true, { uri: event.target });
|
|
215
|
-
} else if (event.operation === FileOperation.DELETE) {
|
|
216
|
-
this.fileDeleteEmitter.fireDid(true, { uri: event.target });
|
|
217
|
-
} else if (event.operation === FileOperation.MOVE && event.source) {
|
|
218
|
-
this.fileMoveEmitter.fireDid(true, { sourceUri: event.source, targetUri: event.target });
|
|
219
|
-
}
|
|
220
|
-
}));
|
|
221
|
-
this.toDispose.push(this.fileService.onDidRunUserOperation(event => {
|
|
222
|
-
if (event.operation === FileOperation.CREATE) {
|
|
223
|
-
this.fileCreateEmitter.fireDid(false, { uri: event.target });
|
|
224
|
-
} else if (event.operation === FileOperation.DELETE) {
|
|
225
|
-
this.fileDeleteEmitter.fireDid(false, { uri: event.target });
|
|
226
|
-
} else if (event.operation === FileOperation.MOVE && event.source) {
|
|
227
|
-
this.fileMoveEmitter.fireDid(false, { sourceUri: event.source, targetUri: event.target });
|
|
228
|
-
}
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Stop watching.
|
|
234
|
-
*/
|
|
235
|
-
dispose(): void {
|
|
236
|
-
this.toDispose.dispose();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Start file watching under the given uri.
|
|
241
|
-
*
|
|
242
|
-
* Resolve when watching is started.
|
|
243
|
-
* Return a disposable to stop file watching under the given uri.
|
|
244
|
-
*/
|
|
245
|
-
async watchFileChanges(uri: URI): Promise<Disposable> {
|
|
246
|
-
return this.fileService.watch(uri);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as path from 'path';
|
|
18
|
-
import * as crypto from 'crypto';
|
|
19
|
-
import * as fs from '@theia/core/shared/fs-extra';
|
|
20
|
-
import { Buffer } from 'buffer';
|
|
21
|
-
import { Disposable } from '@theia/core/lib/common/disposable';
|
|
22
|
-
import { FileUri } from '@theia/core/lib/node/file-uri';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated since 1.17.0
|
|
26
|
-
*/
|
|
27
|
-
export class NodeFileUpload implements Disposable {
|
|
28
|
-
|
|
29
|
-
readonly id: string;
|
|
30
|
-
readonly fsPath: string;
|
|
31
|
-
readonly uploadPath: string;
|
|
32
|
-
protected _uploadedBytes = 0;
|
|
33
|
-
get uploadedBytes(): number {
|
|
34
|
-
return this._uploadedBytes;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
readonly uri: string,
|
|
39
|
-
readonly size: number
|
|
40
|
-
) {
|
|
41
|
-
this.fsPath = FileUri.fsPath(uri);
|
|
42
|
-
this.id = 'theia_upload_' + crypto.randomBytes(16).toString('hex');
|
|
43
|
-
this.uploadPath = path.join(path.dirname(this.fsPath), this.id);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async create(): Promise<void> {
|
|
47
|
-
await fs.outputFile(this.uploadPath, '');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async append(chunk: ArrayBuffer): Promise<void> {
|
|
51
|
-
await fs.appendFile(this.uploadPath, Buffer.from(chunk));
|
|
52
|
-
this._uploadedBytes += chunk.byteLength;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async rename(): Promise<void> {
|
|
56
|
-
await fs.move(this.uploadPath, this.fsPath, { overwrite: true });
|
|
57
|
-
this.dispose = () => Promise.resolve();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
dispose(): void {
|
|
61
|
-
fs.unlink(this.uploadPath).catch(() => {/* no-op */ });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|