How to use the @theia/core/lib/node.FileUri.fsPath function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
it('Moving a non-empty directory to a non-empty directory. Should be rejected because the target location is not empty.', async () => {
            const sourceUri = root.resolve('foo');
            const targetUri = root.resolve('bar');
            const sourceFileUri_01 = sourceUri.resolve('foo_01.txt');
            const sourceFileUri_02 = sourceUri.resolve('foo_02.txt');
            const targetFileUri_01 = targetUri.resolve('bar_01.txt');
            const targetFileUri_02 = targetUri.resolve('bar_02.txt');
            fs.mkdirSync(FileUri.fsPath(sourceUri));
            fs.mkdirSync(FileUri.fsPath(targetUri));
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_01), 'foo_01');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_02), 'foo_02');
            fs.writeFileSync(FileUri.fsPath(targetFileUri_01), 'bar_01');
            fs.writeFileSync(FileUri.fsPath(targetFileUri_02), 'bar_02');
            expect(fs.statSync(FileUri.fsPath(sourceUri)).isDirectory()).to.be.true;
            expect(fs.statSync(FileUri.fsPath(targetUri)).isDirectory()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(sourceFileUri_01), 'utf8')).to.be.equal('foo_01');
            expect(fs.readFileSync(FileUri.fsPath(sourceFileUri_02), 'utf8')).to.be.equal('foo_02');
            expect(fs.readFileSync(FileUri.fsPath(targetFileUri_01), 'utf8')).to.be.equal('bar_01');
            expect(fs.readFileSync(FileUri.fsPath(targetFileUri_02), 'utf8')).to.be.equal('bar_02');
            expect(fs.readdirSync(FileUri.fsPath(sourceUri))).to.include('foo_01.txt').and.to.include('foo_02.txt');
            expect(fs.readdirSync(FileUri.fsPath(targetUri))).to.include('bar_01.txt').and.to.include('bar_02.txt');

            await expectThrowsAsync(fileSystem.move(sourceUri.toString(), targetUri.toString(), { overwrite: true }), Error);
        });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
it('Moving a non-empty directory to file. Should be rejected with an error because directories cannot be moved to existing file locations.', async () => {
            const sourceUri = root.resolve('foo');
            const targetUri = root.resolve('bar.txt');
            const sourceFileUri_01 = sourceUri.resolve('foo_01.txt');
            const sourceFileUri_02 = sourceUri.resolve('foo_02.txt');
            fs.mkdirSync(FileUri.fsPath(sourceUri));
            fs.writeFileSync(FileUri.fsPath(targetUri), 'bar');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_01), 'foo_01');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_02), 'foo_02');
            expect(fs.statSync(FileUri.fsPath(sourceUri)).isDirectory()).to.be.true;
            expect(fs.statSync(FileUri.fsPath(targetUri)).isFile()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(targetUri), 'utf8')).to.be.equal('bar');
            expect(fs.readdirSync(FileUri.fsPath(sourceUri))).to.include('foo_01.txt').and.to.include('foo_02.txt');

            await expectThrowsAsync(fileSystem.move(sourceUri.toString(), targetUri.toString(), { overwrite: true }), Error);
        });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
it('Should delete a directory with all its content.', async () => {
            const uri = root.resolve('foo');
            const subUri = uri.resolve('bar.txt');
            fs.mkdirSync(FileUri.fsPath(uri));
            fs.writeFileSync(FileUri.fsPath(subUri), 'bar');
            expect(fs.statSync(FileUri.fsPath(uri)).isDirectory()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(subUri), 'utf8')).to.be.equal('bar');

            await fileSystem.delete(uri.toString(), { moveToTrash: false });
            expect(fs.existsSync(FileUri.fsPath(uri))).to.be.false;
            expect(fs.existsSync(FileUri.fsPath(subUri))).to.be.false;
        });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
it('Moving a non-empty directory to file. Should be rejected with an error because directories cannot be moved to existing file locations.', async () => {
            const sourceUri = root.resolve('foo');
            const targetUri = root.resolve('bar.txt');
            const sourceFileUri_01 = sourceUri.resolve('foo_01.txt');
            const sourceFileUri_02 = sourceUri.resolve('foo_02.txt');
            fs.mkdirSync(FileUri.fsPath(sourceUri));
            fs.writeFileSync(FileUri.fsPath(targetUri), 'bar');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_01), 'foo_01');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_02), 'foo_02');
            expect(fs.statSync(FileUri.fsPath(sourceUri)).isDirectory()).to.be.true;
            expect(fs.statSync(FileUri.fsPath(targetUri)).isFile()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(targetUri), 'utf8')).to.be.equal('bar');
            expect(fs.readdirSync(FileUri.fsPath(sourceUri))).to.include('foo_01.txt').and.to.include('foo_02.txt');

            await expectThrowsAsync(fileSystem.move(sourceUri.toString(), targetUri.toString(), { overwrite: true }), Error);
        });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
it('Should be return with the stat object for an existing file.', async () => {
            const uri = root.resolve('foo.txt');
            fs.writeFileSync(FileUri.fsPath(uri), 'foo', { encoding: 'utf8' });
            expect(fs.existsSync(FileUri.fsPath(uri))).to.be.true;
            expect(fs.statSync(FileUri.fsPath(uri)).isFile()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(uri), { encoding: 'utf8' }))
                .to.be.equal('foo');

            const content = await fileSystem.resolveContent(uri.toString());
            expect(content).to.be.an('object');
            expect(content).to.have.property('stat');
            expect(content).to.have.property('stat')
                .that.has.property('uri')
                .that.is.equal(uri.toString());
            expect(content).to.have.property('stat')
                .that.has.property('size')
                .that.is.greaterThan(1);
            expect(content).to.have.property('stat')
                .that.has.property('lastModification')
                .that.is.greaterThan(1);
            expect(content).to.have.property('stat')
                .that.has.property('isDirectory')
github eclipse-theia / theia / packages / filesystem / src / node / nsfw-watcher / nsfw-filesystem-watcher.spec.ts View on Github external
const expectedUris = [
            root.resolve('foo').toString(),
            root.withPath(root.path.join('foo', 'bar')).toString(),
            root.withPath(root.path.join('foo', 'bar', 'baz.txt')).toString()
        ];

        fs.mkdirSync(FileUri.fsPath(root.resolve('foo')));
        expect(fs.statSync(FileUri.fsPath(root.resolve('foo'))).isDirectory()).to.be.true;
        await sleep(2000);

        fs.mkdirSync(FileUri.fsPath(root.resolve('foo').resolve('bar')));
        expect(fs.statSync(FileUri.fsPath(root.resolve('foo').resolve('bar'))).isDirectory()).to.be.true;
        await sleep(2000);

        fs.writeFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'baz');
        expect(fs.readFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'utf8')).to.be.equal('baz');
        await sleep(2000);

        assert.deepEqual(expectedUris, [...actualUris]);
    });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
const subSourceUri = sourceUri.resolve('foo_01.txt');
            fs.mkdirSync(FileUri.fsPath(sourceUri));
            fs.writeFileSync(FileUri.fsPath(subSourceUri), 'foo');
            expect(fs.statSync(FileUri.fsPath(sourceUri)).isDirectory()).to.be.true;
            expect(fs.statSync(FileUri.fsPath(subSourceUri)).isFile()).to.be.true;
            expect(fs.readFileSync(FileUri.fsPath(subSourceUri), 'utf8')).to.be.equal('foo');
            expect(fs.existsSync(FileUri.fsPath(targetUri))).to.be.false;

            const stat = await fileSystem.copy(sourceUri.toString(), targetUri.toString());
            expect(stat).to.be.an('object');
            expect(stat).to.have.property('uri').that.is.equal(targetUri.toString());
            expect(fs.existsSync(FileUri.fsPath(sourceUri))).to.be.true;
            expect(fs.existsSync(FileUri.fsPath(targetUri))).to.be.true;
            expect(fs.readdirSync(FileUri.fsPath(sourceUri))).to.contain('foo_01.txt');
            expect(fs.readdirSync(FileUri.fsPath(targetUri))).to.contain('foo_01.txt');
            expect(fs.readFileSync(FileUri.fsPath(subSourceUri), 'utf8')).to.be.equal('foo');
            expect(fs.readFileSync(FileUri.fsPath(targetUri.resolve('foo_01.txt')), 'utf8')).to.be.equal('foo');
        });
github eclipse-theia / theia / packages / filesystem / src / node / nsfw-watcher / nsfw-filesystem-watcher.spec.ts View on Github external
}
        };
        watcherServer.setClient(watcherClient);

        const expectedUris = [
            root.resolve('foo').toString(),
            root.withPath(root.path.join('foo', 'bar')).toString(),
            root.withPath(root.path.join('foo', 'bar', 'baz.txt')).toString()
        ];

        fs.mkdirSync(FileUri.fsPath(root.resolve('foo')));
        expect(fs.statSync(FileUri.fsPath(root.resolve('foo'))).isDirectory()).to.be.true;
        await sleep(2000);

        fs.mkdirSync(FileUri.fsPath(root.resolve('foo').resolve('bar')));
        expect(fs.statSync(FileUri.fsPath(root.resolve('foo').resolve('bar'))).isDirectory()).to.be.true;
        await sleep(2000);

        fs.writeFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'baz');
        expect(fs.readFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'utf8')).to.be.equal('baz');
        await sleep(2000);

        assert.deepEqual(expectedUris, [...actualUris]);
    });
github eclipse-theia / theia / packages / filesystem / src / node / node-filesystem.spec.ts View on Github external
return;
            }
            const sourceUri = root.resolve('foo');
            const targetUri = root.resolve('bar');
            const sourceFileUri_01 = sourceUri.resolve('foo_01.txt');
            const sourceFileUri_02 = sourceUri.resolve('foo_02.txt');
            fs.mkdirSync(FileUri.fsPath(sourceUri));
            fs.mkdirSync(FileUri.fsPath(targetUri));
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_01), 'foo_01');
            fs.writeFileSync(FileUri.fsPath(sourceFileUri_02), 'foo_02');
            expect(fs.statSync(FileUri.fsPath(sourceUri)).isDirectory()).to.be.true;
            expect(fs.statSync(FileUri.fsPath(targetUri)).isDirectory()).to.be.true;
            expect(fs.readdirSync(FileUri.fsPath(targetUri))).to.be.empty;
            expect(fs.readdirSync(FileUri.fsPath(sourceUri))).to.include('foo_01.txt').and.to.include('foo_02.txt');
            expect(fs.readFileSync(FileUri.fsPath(sourceFileUri_01), 'utf8')).to.be.equal('foo_01');
            expect(fs.readFileSync(FileUri.fsPath(sourceFileUri_02), 'utf8')).to.be.equal('foo_02');

            const stat = await fileSystem.move(sourceUri.toString(), targetUri.toString(), { overwrite: true });
            expect(stat).is.an('object').and.has.property('uri').that.equals(targetUri.toString());
            expect(fs.existsSync(FileUri.fsPath(sourceUri))).to.be.false;
            expect(fs.statSync(FileUri.fsPath(targetUri)).isDirectory()).to.be.true;
            expect(fs.readdirSync(FileUri.fsPath(targetUri))).to.include('foo_01.txt').and.to.include('foo_02.txt');
            expect(fs.readFileSync(FileUri.fsPath(targetUri.resolve('foo_01.txt')), 'utf8')).to.be.equal('foo_01');
            expect(fs.readFileSync(FileUri.fsPath(targetUri.resolve('foo_02.txt')), 'utf8')).to.be.equal('foo_02');
        });
github eclipse-theia / theia / packages / workspace / src / node / default-workspace-server.ts View on Github external
protected workspaceStillExist(wspath: string): boolean {
        return fs.pathExistsSync(FileUri.fsPath(wspath));
    }