@@ -6,8 +6,8 @@ import { ncp } from 'ncp';
6
6
import { Stats } from 'fs' ;
7
7
import * as fs from './fs-extra' ;
8
8
import URI from '@theia/core/lib/common/uri' ;
9
+ import { FileUri } from '@theia/core/lib/node' ;
9
10
import { isWindows } from '@theia/core/lib/common/os' ;
10
- import { FileUri , BackendApplicationContribution } from '@theia/core/lib/node' ;
11
11
import { ConfigService } from '../common/protocol/config-service' ;
12
12
import { SketchesService , Sketch } from '../common/protocol/sketches-service' ;
13
13
import { firstToLowerCase } from '../common/utils' ;
@@ -23,17 +23,11 @@ const prefix = '.arduinoProIDE-unsaved';
23
23
24
24
// TODO: `fs`: use async API
25
25
@injectable ( )
26
- export class SketchesServiceImpl implements SketchesService , BackendApplicationContribution {
27
-
28
- protected readonly temp = temp . track ( ) ;
26
+ export class SketchesServiceImpl implements SketchesService {
29
27
30
28
@inject ( ConfigService )
31
29
protected readonly configService : ConfigService ;
32
30
33
- onStop ( ) : void {
34
- this . temp . cleanupSync ( ) ;
35
- }
36
-
37
31
async getSketches ( uri ?: string ) : Promise < Sketch [ ] > {
38
32
const sketches : Array < Sketch & { mtimeMs : number } > = [ ] ;
39
33
let fsPath : undefined | string ;
@@ -210,7 +204,7 @@ export class SketchesServiceImpl implements SketchesService, BackendApplicationC
210
204
async cloneExample ( uri : string ) : Promise < Sketch > {
211
205
const sketch = await this . loadSketch ( uri ) ;
212
206
const parentPath = await new Promise < string > ( ( resolve , reject ) => {
213
- this . temp . mkdir ( { prefix } , ( err , dirPath ) => {
207
+ temp . mkdir ( { prefix } , ( err , dirPath ) => {
214
208
if ( err ) {
215
209
reject ( err ) ;
216
210
return ;
@@ -277,7 +271,7 @@ export class SketchesServiceImpl implements SketchesService, BackendApplicationC
277
271
const monthNames = [ 'jan' , 'feb' , 'mar' , 'apr' , 'may' , 'jun' , 'jul' , 'aug' , 'sep' , 'oct' , 'nov' , 'dec' ] ;
278
272
const today = new Date ( ) ;
279
273
const parentPath = await new Promise < string > ( ( resolve , reject ) => {
280
- this . temp . mkdir ( { prefix } , ( err , dirPath ) => {
274
+ temp . mkdir ( { prefix } , ( err , dirPath ) => {
281
275
if ( err ) {
282
276
reject ( err ) ;
283
277
return ;
@@ -373,6 +367,11 @@ void loop() {
373
367
if ( ! exists ) {
374
368
throw new Error ( `Sketch does not exist: ${ sketch } ` ) ;
375
369
}
370
+ // Nothing to do when source and destination are the same.
371
+ if ( sketch . uri === destinationUri ) {
372
+ await this . loadSketch ( sketch . uri ) ; // Sanity check.
373
+ return sketch . uri ;
374
+ }
376
375
const destination = FileUri . fsPath ( destinationUri ) ;
377
376
await new Promise < void > ( ( resolve , reject ) => {
378
377
ncp . ncp ( source , destination , async error => {
@@ -384,9 +383,7 @@ void loop() {
384
383
try {
385
384
const oldPath = path . join ( destination , new URI ( sketch . mainFileUri ) . path . base ) ;
386
385
const newPath = path . join ( destination , `${ newName } .ino` ) ;
387
- if ( oldPath !== newPath ) {
388
- await fs . rename ( oldPath , newPath ) ;
389
- }
386
+ await fs . rename ( oldPath , newPath ) ;
390
387
await this . loadSketch ( destinationUri ) ; // Sanity check.
391
388
resolve ( ) ;
392
389
} catch ( e ) {
0 commit comments