Skip to content

Commit 6e6dcd5

Browse files
rocwindlisong
authored andcommitted
ignore .codepushrelease and other system generated files in calculating folder hash (#182)
谢谢!
1 parent 2e90e36 commit 6e6dcd5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core/utils/security.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ security.uploadPackageType = function (directoryPath) {
146146
});
147147
}
148148

149+
// some files are ignored in calc hash in client sdk
150+
// https://github.com/Microsoft/react-native-code-push/pull/974/files#diff-21b650f88429c071b217d46243875987R15
151+
security.isHashIgnored = function (relativePath) {
152+
if (!relativePath) {
153+
return true;
154+
}
155+
156+
157+
const IgnoreMacOSX = '__MACOSX/';
158+
const IgnoreDSStore = '.DS_Store';
159+
const IgnoreCodePushMetadata = '.codepushrelease';
160+
161+
return relativePath.startsWith(IgnoreMacOSX)
162+
|| relativePath === IgnoreDSStore
163+
|| relativePath.endsWith(IgnoreDSStore)
164+
|| relativePath === IgnoreCodePushMetadata
165+
|| relativePath.endsWith(IgnoreCodePushMetadata);
166+
}
167+
149168
security.calcAllFileSha256 = function (directoryPath) {
150169
return new Promise((resolve, reject) => {
151170
var recursive = require("recursive-readdir");
@@ -156,6 +175,12 @@ security.calcAllFileSha256 = function (directoryPath) {
156175
log.error(error);
157176
reject(new AppError.AppError(error.message));
158177
} else {
178+
// filter files that should be ignored
179+
files = files.filter((file) => {
180+
var relative = path.relative(directoryPath, file);
181+
return !security.isHashIgnored(relative);
182+
});
183+
159184
if (files.length == 0) {
160185
log.debug(`calcAllFileSha256 empty files in directoryPath:`, directoryPath);
161186
reject(new AppError.AppError("empty files"));

0 commit comments

Comments
 (0)