@@ -78,46 +78,53 @@ async function extractTarXzBy7zip(file: string, name: string, dest: string, stri
78
78
throw new Error ( `Invalid tar file: ${ name } ` )
79
79
}
80
80
// extract the compression first
81
- const tarDir = dirname ( file )
81
+ const tarDir = join ( dirname ( file ) , "sevenzip-temp" )
82
82
await run7zip ( file , tarDir )
83
83
// extract the tar
84
84
const tarName = name . slice ( 0 , - 3 )
85
85
const tarFile = join ( tarDir , tarName )
86
86
await run7zip ( tarFile , tarDir )
87
87
await remove ( tarFile )
88
88
// move the extracted files to the destination
89
- const folderName = tarName . slice ( 0 , - 4 )
90
- const folderPath = join ( tarDir , folderName )
91
- info ( `Moving ${ folderPath } to ${ dest } ` )
92
- await move ( folderPath , dest , { overwrite : true } )
89
+ info ( `Moving ${ tarDir } to ${ dest } ` )
90
+ const files = await readdir ( tarDir )
91
+ await Promise . all (
92
+ files . map ( async ( file ) => {
93
+ await move ( join ( tarDir , file ) , join ( dest , file ) , { overwrite : true } )
94
+ } ) ,
95
+ )
96
+ await remove ( tarDir )
93
97
94
98
if ( stripComponents ) {
95
- await stripPathComponents ( dest , folderName )
99
+ await stripPathComponents ( dest )
96
100
}
97
101
}
98
102
99
- async function stripPathComponents ( dest : string , folderName : string ) {
103
+ async function stripPathComponents ( dest : string ) {
104
+ info ( `Stripping path components from ${ dest } ` )
105
+
100
106
// get all subfolders in the folder
101
- const subFolders = await readdir ( join ( dest , folderName ) )
107
+ const toStrip = await readdir ( dest )
108
+ if ( toStrip . length !== 1 ) {
109
+ throw new Error ( `Expected 1 folder in ${ dest } , got ${ toStrip . length } ` )
110
+ }
111
+ const subFolder = toStrip [ 0 ]
112
+ const subFolderPath = join ( dest , subFolder )
113
+ const subFolderStat = await stat ( subFolderPath )
114
+ if ( ! subFolderStat . isDirectory ( ) ) {
115
+ // if the subfolder is not a directory, do nothing
116
+ warning ( `Expected ${ subFolderPath } to be a directory, got ${ subFolderStat } .` )
117
+ return
118
+ }
119
+ // for each child of the subfolder, move all files to the destination
120
+ const subFiles = await readdir ( subFolderPath )
102
121
await Promise . all (
103
- subFolders . map ( async ( subFolder ) => {
104
- const subFolderPath = join ( dest , subFolder )
105
- if ( ! ( await stat ( subFolderPath ) ) . isDirectory ( ) ) {
106
- // if the subfolder is not a directory, do nothing
107
- return
108
- }
109
- // for each subfolder, move all files to the destination
110
- const subFiles = await readdir ( subFolderPath )
111
- await Promise . all (
112
- subFiles . map ( ( subFile ) => {
113
- return move ( join ( subFolderPath , subFile ) , join ( dest , subFile ) , { overwrite : true } )
114
- } ) ,
115
- )
116
- // remove the subfolder
117
- await remove ( subFolderPath )
118
- return
122
+ subFiles . map ( ( subFile ) => {
123
+ return move ( join ( subFolderPath , subFile ) , join ( dest , subFile ) , { overwrite : true } )
119
124
} ) ,
120
125
)
126
+ // remove the subfolder
127
+ await remove ( subFolderPath )
121
128
}
122
129
123
130
async function run7zip ( file : string , dest : string ) {
0 commit comments