@@ -8,7 +8,7 @@ const readChunk = require(`read-chunk`)
88const fileType = require ( `file-type` )
99
1010const { createFileNode } = require ( `./create-file-node` )
11- const { getRemoteFileExtension } = require ( `./utils` )
11+ const { getRemoteFileExtension, getRemoteFileName } = require ( `./utils` )
1212const cacheId = url => `create-remote-file-node-${ url } `
1313
1414/********************
@@ -75,7 +75,7 @@ const FS_PLUGIN_DIR = `gatsby-source-filesystem`
7575 * @return {String }
7676 */
7777const createFilePath = ( directory , filename , ext ) =>
78- path . join ( directory , CACHE_DIR , FS_PLUGIN_DIR , `${ filename } ${ ext } ` )
78+ path . join ( directory , `${ filename } ${ ext } ` )
7979
8080/********************
8181 * Queue Management *
@@ -178,8 +178,12 @@ async function processRemoteNode({
178178 ext,
179179} ) {
180180 // Ensure our cache directory exists.
181- const programDir = store . getState ( ) . program . directory
182- await fs . ensureDir ( path . join ( programDir , CACHE_DIR , FS_PLUGIN_DIR ) )
181+ const pluginCacheDir = path . join (
182+ store . getState ( ) . program . directory ,
183+ CACHE_DIR ,
184+ FS_PLUGIN_DIR
185+ )
186+ await fs . ensureDir ( pluginCacheDir )
183187
184188 // See if there's response headers for this url
185189 // from a previous request.
@@ -198,11 +202,12 @@ async function processRemoteNode({
198202
199203 // Create the temp and permanent file names for the url.
200204 const digest = createHash ( url )
205+ const name = getRemoteFileName ( url )
201206 if ( ! ext ) {
202207 ext = getRemoteFileExtension ( url )
203208 }
204209
205- const tmpFilename = createFilePath ( programDir , `tmp-${ digest } ` , ext )
210+ const tmpFilename = createFilePath ( pluginCacheDir , `tmp-${ digest } ` , ext )
206211
207212 // Fetch the file.
208213 try {
@@ -218,7 +223,12 @@ async function processRemoteNode({
218223 ext = `.${ filetype . ext } `
219224 }
220225 }
221- const filename = createFilePath ( programDir , digest , ext )
226+
227+ const filename = createFilePath (
228+ path . join ( pluginCacheDir , digest ) ,
229+ name ,
230+ ext
231+ )
222232 // If the status code is 200, move the piped temp file to the real name.
223233 if ( response . statusCode === 200 ) {
224234 await fs . move ( tmpFilename , filename , { overwrite : true } )
0 commit comments