Skip to content

Commit 80cbf1f

Browse files
Replace now checks file by file (#4)
* Replace now checks file by file * added some more logs * compile * add more logs * bump changes * bump action * bump action * update action * it works * updated action * bump action * fixed log level for action
1 parent ee2c229 commit 80cbf1f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ async function run() {
8080
} else {
8181
isDirectory = await pathIsDirectory(file.source)
8282

83-
if (destExists === true && file.replace === false) return core.warning(`File(s) already exist(s) in destination and 'replace' option is set to false`)
84-
8583
const source = isDirectory ? `${ addTrailingSlash(file.source) }` : file.source
8684
const dest = isDirectory ? `${ addTrailingSlash(localDestination) }` : localDestination
8785

0 commit comments

Comments
 (0)