@@ -21,12 +21,35 @@ export class ExportBase implements IExport {
21
21
public async export ( _source : Uri , _target : Uri ) : Promise < void > { }
22
22
23
23
@reportAction ( ReportableAction . PerformingExport )
24
- public async executeCommand ( source : Uri , args : string [ ] ) : Promise < void > {
24
+ public async executeCommand ( source : Uri , target : Uri , args : string [ ] ) : Promise < void > {
25
25
const service = await this . getExecutionService ( source ) ;
26
26
if ( ! service ) {
27
27
return ;
28
28
}
29
- await service . execModule ( 'jupyter' , [ 'nbconvert' ] . concat ( args ) , { throwOnStdErr : false , encoding : 'utf8' } ) ;
29
+
30
+ const oldFileExists = await this . fileSystem . fileExists ( target . fsPath ) ;
31
+ let oldFileTime ;
32
+ if ( oldFileExists ) {
33
+ oldFileTime = ( await this . fileSystem . stat ( target . fsPath ) ) . mtime ;
34
+ }
35
+
36
+ const result = await service . execModule ( 'jupyter' , [ 'nbconvert' ] . concat ( args ) , {
37
+ throwOnStdErr : false ,
38
+ encoding : 'utf8'
39
+ } ) ;
40
+
41
+ // Need to check if export failed, since throwOnStdErr is not an
42
+ // indicator of a failed export.
43
+ if ( ! ( await this . fileSystem . fileExists ( target . fsPath ) ) ) {
44
+ throw new Error ( result . stderr ) ;
45
+ } else if ( oldFileExists ) {
46
+ // If we exported to a file that already exists we need to check that
47
+ // this file was actually overriden during export
48
+ const newFileTime = ( await this . fileSystem . stat ( target . fsPath ) ) . mtime ;
49
+ if ( newFileTime === oldFileTime ) {
50
+ throw new Error ( result . stderr ) ;
51
+ }
52
+ }
30
53
}
31
54
32
55
protected async getExecutionService ( source : Uri ) : Promise < IPythonExecutionService | undefined > {
0 commit comments