@@ -23,7 +23,7 @@ import {
23
23
templateVersionVariables ,
24
24
} from "api/queries/templates" ;
25
25
import { file , uploadFile } from "api/queries/files" ;
26
- import { TarFileTypeCodes , TarReader , TarWriter } from "utils/tar" ;
26
+ import { TarReader , TarWriter } from "utils/tar" ;
27
27
import { FileTree , traverse } from "utils/filetree" ;
28
28
import { createTemplateVersionFileTree } from "utils/templateVersion" ;
29
29
import { displayError } from "components/GlobalSnackbar/utils" ;
@@ -78,6 +78,13 @@ export const TemplateVersionEditorPage: FC = () => {
78
78
const [ lastSuccessfulPublishedVersion , setLastSuccessfulPublishedVersion ] =
79
79
useState < TemplateVersion > ( ) ;
80
80
81
+ const navigateToVersion = ( version : TemplateVersion ) => {
82
+ return navigate (
83
+ `/templates/${ templateName } /versions/${ version . name } /edit` ,
84
+ { replace : true } ,
85
+ ) ;
86
+ } ;
87
+
81
88
// Optimistically update the template version data job status to make the
82
89
// build action feels faster
83
90
const onBuildStart = ( ) => {
@@ -97,6 +104,7 @@ export const TemplateVersionEditorPage: FC = () => {
97
104
const onBuildEnds = ( newVersion : TemplateVersion ) => {
98
105
setCurrentVersionName ( newVersion . name ) ;
99
106
queryClient . setQueryData ( templateVersionOptions . queryKey , newVersion ) ;
107
+ navigateToVersion ( newVersion ) ;
100
108
} ;
101
109
102
110
// Provisioner Tags
@@ -163,10 +171,7 @@ export const TemplateVersionEditorPage: FC = () => {
163
171
templateVersionOptions . queryKey ,
164
172
publishedVersion ,
165
173
) ;
166
- navigate (
167
- `/templates/${ templateName } /versions/${ publishedVersion . name } /edit` ,
168
- { replace : true } ,
169
- ) ;
174
+ navigateToVersion ( publishedVersion ) ;
170
175
} }
171
176
isAskingPublishParameters = { isPublishingDialogOpen }
172
177
isPublishing = { publishVersionMutation . isLoading }
@@ -328,37 +333,20 @@ const generateVersionFiles = async (
328
333
) => {
329
334
const tar = new TarWriter ( ) ;
330
335
331
- // Add previous non editable files
332
- for ( const file of tarReader . fileInfo ) {
333
- if ( file . type === TarFileTypeCodes . Dir ) {
334
- tar . addFolder ( file . name , {
335
- mode : file . mode , // https://github.com/beatgammit/tar-js/blob/master/lib/tar.js#L42
336
- mtime : file . mtime ,
337
- user : file . user ,
338
- group : file . group ,
339
- } ) ;
340
- } else {
341
- tar . addFile ( file . name , tarReader . getTextFile ( file . name ) as string , {
342
- mode : file . mode , // https://github.com/beatgammit/tar-js/blob/master/lib/tar.js#L42
343
- mtime : file . mtime ,
344
- user : file . user ,
345
- group : file . group ,
346
- } ) ;
347
- }
348
- }
349
- // Add the editable files
350
336
traverse ( fileTree , ( content , _filename , fullPath ) => {
351
337
// When a file is deleted. Don't add it to the tar.
352
338
if ( content === undefined ) {
353
339
return ;
354
340
}
355
341
342
+ const baseFileInfo = tarReader . fileInfo . find ( ( i ) => i . name === fullPath ) ;
343
+
356
344
if ( typeof content === "string" ) {
357
- tar . addFile ( fullPath , content ) ;
345
+ tar . addFile ( fullPath , content , baseFileInfo ) ;
358
346
return ;
359
347
}
360
348
361
- tar . addFolder ( fullPath ) ;
349
+ tar . addFolder ( fullPath , baseFileInfo ) ;
362
350
} ) ;
363
351
const blob = ( await tar . write ( ) ) as Blob ;
364
352
return new File ( [ blob ] , "template.tar" ) ;
0 commit comments