@@ -81,30 +81,48 @@ export async function copy(src, dest, isDirectory, file) {
8181 const deleteOrphaned = isDirectory && file . deleteOrphaned
8282 const exclude = file . exclude
8383
84- const filterFunc = ( file ) => {
84+ const filterFunc = ( srcFile , destFile ) => {
85+ core . debug ( `Filtering file ${ srcFile } to ${ destFile } ` )
86+ if ( file . replace === false ) {
87+ // Directories are always copied
88+ try {
89+ if ( fs . lstatSync ( destFile ) . isDirectory ( ) ) {
90+ core . debug ( `Dest File ${ destFile } already exists and is a directory` )
91+ return true
92+ }
93+ } catch ( error ) {
94+ core . debug ( `Destination file or directory ${ destFile } does not exist` )
95+ return true
96+ }
97+
98+ if ( fs . existsSync ( destFile ) ) {
99+ core . debug ( `File ${ destFile } already exists and 'replace' option is set to false` )
100+ return false
101+ }
102+ }
85103
86104 if ( exclude !== undefined ) {
87105
88106 // Check if file-path is one of the present filepaths in the excluded paths
89107 // This has presedence over the single file, and therefore returns before the single file check
90108 let filePath = ''
91- if ( file . endsWith ( '/' ) ) {
109+ if ( srcFile . endsWith ( '/' ) ) {
92110 // File item is a folder
93- filePath = file
111+ filePath = srcFile
94112 } else {
95113 // File item is a file
96- filePath = file . split ( '\/' ) . slice ( 0 , - 1 ) . join ( '/' ) + '/'
114+ filePath = srcFile . split ( '\/' ) . slice ( 0 , - 1 ) . join ( '/' ) + '/'
97115 }
98116
99117 if ( exclude . includes ( filePath ) ) {
100- core . debug ( `Excluding file ${ file } since its path is included as one of the excluded paths.` )
118+ core . debug ( `Excluding file ${ srcFile } since its path is included as one of the excluded paths.` )
101119 return false
102120 }
103121
104122
105123 // Or if the file itself is in the excluded files
106- if ( exclude . includes ( file ) ) {
107- core . debug ( `Excluding file ${ file } since it is explicitly added in the exclusion list.` )
124+ if ( exclude . includes ( srcFile ) ) {
125+ core . debug ( `Excluding file ${ srcFile } since it is explicitly added in the exclusion list.` )
108126 return false
109127 }
110128 }
@@ -130,7 +148,7 @@ export async function copy(src, dest, isDirectory, file) {
130148 }
131149 } else {
132150 core . debug ( `Copy ${ src } to ${ dest } ` )
133- await fs . copy ( src , dest , file . exclude !== undefined && { filter : filterFunc } )
151+ await fs . copy ( src , dest , { filter : filterFunc } )
134152 }
135153
136154
0 commit comments