@theia/filesystem 1.26.0-next.9 → 1.26.0
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/breadcrumbs/filepath-breadcrumbs-container.d.ts +1 -2
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-container.d.ts.map +1 -1
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-container.js +3 -4
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-container.js.map +1 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.d.ts +1 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.js +1 -1
- 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/browser/location/location-renderer.js +2 -2
- package/lib/browser/location/location-renderer.js.map +1 -1
- package/lib/common/filesystem-utils.spec.js +49 -49
- package/lib/common/filesystem-utils.spec.js.map +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/package.json +4 -4
- package/src/browser/breadcrumbs/filepath-breadcrumbs-container.ts +1 -2
- package/src/browser/file-tree/file-tree-decorator-adapter.ts +1 -1
- 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/browser/location/location-renderer.tsx +2 -2
- package/src/common/filesystem-utils.spec.ts +1 -1
- package/src/common/filesystem-watcher-protocol.ts +1 -67
- package/src/common/filesystem.ts +0 -259
- 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,255 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017-2018 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 fs from 'fs';
|
|
18
|
-
import * as nsfw from '@theia/core/shared/nsfw';
|
|
19
|
-
import * as paths from 'path';
|
|
20
|
-
import { IMinimatch, Minimatch } from 'minimatch';
|
|
21
|
-
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
22
|
-
import { FileUri } from '@theia/core/lib/node/file-uri';
|
|
23
|
-
import {
|
|
24
|
-
FileChangeType,
|
|
25
|
-
FileSystemWatcherClient,
|
|
26
|
-
FileSystemWatcherServer,
|
|
27
|
-
WatchOptions
|
|
28
|
-
} from '../../common/filesystem-watcher-protocol';
|
|
29
|
-
import { FileChangeCollection } from '../file-change-collection';
|
|
30
|
-
import { setInterval, clearInterval } from 'timers';
|
|
31
|
-
|
|
32
|
-
import debounce = require('@theia/core/shared/lodash.debounce');
|
|
33
|
-
|
|
34
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated since 1.6.0
|
|
38
|
-
*/
|
|
39
|
-
export interface WatcherOptions {
|
|
40
|
-
ignored: IMinimatch[]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated since 1.6.0 use `NsfwFileSystemWatcherService` instead.
|
|
45
|
-
*/
|
|
46
|
-
export class NsfwFileSystemWatcherServer implements FileSystemWatcherServer {
|
|
47
|
-
|
|
48
|
-
protected client: FileSystemWatcherClient | undefined;
|
|
49
|
-
|
|
50
|
-
protected watcherSequence = 1;
|
|
51
|
-
protected readonly watchers = new Map<number, Disposable>();
|
|
52
|
-
protected readonly watcherOptions = new Map<number, WatcherOptions>();
|
|
53
|
-
|
|
54
|
-
protected readonly toDispose = new DisposableCollection(
|
|
55
|
-
Disposable.create(() => this.setClient(undefined))
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
protected changes = new FileChangeCollection();
|
|
59
|
-
|
|
60
|
-
protected readonly options: {
|
|
61
|
-
verbose: boolean
|
|
62
|
-
info: (message: string, ...args: any[]) => void
|
|
63
|
-
error: (message: string, ...args: any[]) => void,
|
|
64
|
-
nsfwOptions: nsfw.Options
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
constructor(options?: {
|
|
68
|
-
verbose?: boolean,
|
|
69
|
-
nsfwOptions?: nsfw.Options,
|
|
70
|
-
info?: (message: string, ...args: any[]) => void
|
|
71
|
-
error?: (message: string, ...args: any[]) => void
|
|
72
|
-
}) {
|
|
73
|
-
this.options = {
|
|
74
|
-
nsfwOptions: {},
|
|
75
|
-
verbose: false,
|
|
76
|
-
info: (message, ...args) => console.info(message, ...args),
|
|
77
|
-
error: (message, ...args) => console.error(message, ...args),
|
|
78
|
-
...options
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
dispose(): void {
|
|
83
|
-
this.toDispose.dispose();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async watchFileChanges(uri: string, options?: WatchOptions): Promise<number> {
|
|
87
|
-
const watcherId = this.watcherSequence++;
|
|
88
|
-
const basePath = FileUri.fsPath(uri);
|
|
89
|
-
this.debug('Starting watching:', basePath);
|
|
90
|
-
const toDisposeWatcher = new DisposableCollection();
|
|
91
|
-
this.watchers.set(watcherId, toDisposeWatcher);
|
|
92
|
-
toDisposeWatcher.push(Disposable.create(() => this.watchers.delete(watcherId)));
|
|
93
|
-
if (fs.existsSync(basePath)) {
|
|
94
|
-
this.start(watcherId, basePath, options, toDisposeWatcher);
|
|
95
|
-
} else {
|
|
96
|
-
const toClearTimer = new DisposableCollection();
|
|
97
|
-
const timer = setInterval(() => {
|
|
98
|
-
if (fs.existsSync(basePath)) {
|
|
99
|
-
toClearTimer.dispose();
|
|
100
|
-
this.pushAdded(watcherId, basePath);
|
|
101
|
-
this.start(watcherId, basePath, options, toDisposeWatcher);
|
|
102
|
-
}
|
|
103
|
-
}, 500);
|
|
104
|
-
toClearTimer.push(Disposable.create(() => clearInterval(timer)));
|
|
105
|
-
toDisposeWatcher.push(toClearTimer);
|
|
106
|
-
}
|
|
107
|
-
this.toDispose.push(toDisposeWatcher);
|
|
108
|
-
return watcherId;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
protected async start(watcherId: number, basePath: string, rawOptions: WatchOptions | undefined, toDisposeWatcher: DisposableCollection): Promise<void> {
|
|
112
|
-
const options: WatchOptions = {
|
|
113
|
-
ignored: [],
|
|
114
|
-
...rawOptions
|
|
115
|
-
};
|
|
116
|
-
if (options.ignored.length > 0) {
|
|
117
|
-
this.debug('Files ignored for watching', options.ignored);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.FileChangeEvent[]) => {
|
|
121
|
-
for (const event of events) {
|
|
122
|
-
if (event.action === nsfw.actions.CREATED) {
|
|
123
|
-
this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));
|
|
124
|
-
}
|
|
125
|
-
if (event.action === nsfw.actions.DELETED) {
|
|
126
|
-
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file!));
|
|
127
|
-
}
|
|
128
|
-
if (event.action === nsfw.actions.MODIFIED) {
|
|
129
|
-
this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file!));
|
|
130
|
-
}
|
|
131
|
-
if (event.action === nsfw.actions.RENAMED) {
|
|
132
|
-
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile!));
|
|
133
|
-
this.pushAdded(watcherId, this.resolvePath(event.newDirectory || event.directory, event.newFile!));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
|
-
errorCallback: error => {
|
|
138
|
-
// see https://github.com/atom/github/issues/342
|
|
139
|
-
console.warn(`Failed to watch "${basePath}":`, error);
|
|
140
|
-
if (error === 'Inotify limit reached') {
|
|
141
|
-
if (this.client) {
|
|
142
|
-
this.client.onError();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
this.unwatchFileChanges(watcherId);
|
|
146
|
-
},
|
|
147
|
-
...this.options.nsfwOptions
|
|
148
|
-
});
|
|
149
|
-
await watcher.start();
|
|
150
|
-
this.options.info('Started watching:', basePath);
|
|
151
|
-
if (toDisposeWatcher.disposed) {
|
|
152
|
-
this.debug('Stopping watching:', basePath);
|
|
153
|
-
await watcher.stop();
|
|
154
|
-
// remove a reference to nsfw otherwise GC cannot collect it
|
|
155
|
-
watcher = undefined;
|
|
156
|
-
this.options.info('Stopped watching:', basePath);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
toDisposeWatcher.push(Disposable.create(async () => {
|
|
160
|
-
this.watcherOptions.delete(watcherId);
|
|
161
|
-
if (watcher) {
|
|
162
|
-
this.debug('Stopping watching:', basePath);
|
|
163
|
-
await watcher.stop();
|
|
164
|
-
// remove a reference to nsfw otherwise GC cannot collect it
|
|
165
|
-
watcher = undefined;
|
|
166
|
-
this.options.info('Stopped watching:', basePath);
|
|
167
|
-
}
|
|
168
|
-
}));
|
|
169
|
-
this.watcherOptions.set(watcherId, {
|
|
170
|
-
ignored: options.ignored.map(pattern => new Minimatch(pattern, { dot: true }))
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
unwatchFileChanges(watcherId: number): Promise<void> {
|
|
175
|
-
const disposable = this.watchers.get(watcherId);
|
|
176
|
-
if (disposable) {
|
|
177
|
-
this.watchers.delete(watcherId);
|
|
178
|
-
disposable.dispose();
|
|
179
|
-
}
|
|
180
|
-
return Promise.resolve();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
setClient(client: FileSystemWatcherClient | undefined): void {
|
|
184
|
-
if (client && this.toDispose.disposed) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
this.client = client;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
protected pushAdded(watcherId: number, path: string): void {
|
|
191
|
-
this.debug('Added:', path);
|
|
192
|
-
this.pushFileChange(watcherId, path, FileChangeType.ADDED);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
protected pushUpdated(watcherId: number, path: string): void {
|
|
196
|
-
this.debug('Updated:', path);
|
|
197
|
-
this.pushFileChange(watcherId, path, FileChangeType.UPDATED);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
protected pushDeleted(watcherId: number, path: string): void {
|
|
201
|
-
this.debug('Deleted:', path);
|
|
202
|
-
this.pushFileChange(watcherId, path, FileChangeType.DELETED);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
protected pushFileChange(watcherId: number, path: string, type: FileChangeType): void {
|
|
206
|
-
if (this.isIgnored(watcherId, path)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const uri = FileUri.create(path).toString();
|
|
211
|
-
this.changes.push({ uri, type });
|
|
212
|
-
|
|
213
|
-
this.fireDidFilesChanged();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
protected resolvePath(directory: string, file: string): string {
|
|
217
|
-
const path = paths.join(directory, file);
|
|
218
|
-
try {
|
|
219
|
-
return fs.realpathSync(path);
|
|
220
|
-
} catch {
|
|
221
|
-
try {
|
|
222
|
-
// file does not exist try to resolve directory
|
|
223
|
-
return paths.join(fs.realpathSync(directory), file);
|
|
224
|
-
} catch {
|
|
225
|
-
// directory does not exist fall back to symlink
|
|
226
|
-
return path;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Fires file changes to clients.
|
|
233
|
-
* It is debounced in the case if the filesystem is spamming to avoid overwhelming clients with events.
|
|
234
|
-
*/
|
|
235
|
-
protected readonly fireDidFilesChanged: () => void = debounce(() => this.doFireDidFilesChanged(), 50);
|
|
236
|
-
protected doFireDidFilesChanged(): void {
|
|
237
|
-
const changes = this.changes.values();
|
|
238
|
-
this.changes = new FileChangeCollection();
|
|
239
|
-
const event = { changes };
|
|
240
|
-
if (this.client) {
|
|
241
|
-
this.client.onDidFilesChanged(event);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
protected isIgnored(watcherId: number, path: string): boolean {
|
|
246
|
-
const options = this.watcherOptions.get(watcherId);
|
|
247
|
-
return !!options && options.ignored.length > 0 && options.ignored.some(m => m.match(path));
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
protected debug(message: string, ...params: any[]): void {
|
|
251
|
-
if (this.options.verbose) {
|
|
252
|
-
this.options.info(message, ...params);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|