Cover rename and deleted directory cases

This commit is contained in:
oldmud0 2019-04-03 22:58:05 -05:00
parent f4b31356df
commit 9b4c18e8dc
2 changed files with 55 additions and 17 deletions

View File

@ -30,7 +30,7 @@ argParser.addArgument([ "-f", "--full" ], {
});
argParser.addArgument([ "-i", "--incremental" ], {
type: isFile, nargs: 2, dest: "incrementalArgs",
metavar: ["<incremental zip file>", "<file containing list of deleted files>"]
metavar: ["<incremental zip file>", "<file containing list of changed files>"]
});
argParser.addArgument([ "-e", "--executable" ], {
metavar: "[executable file]", nargs: 1,
@ -45,7 +45,7 @@ const {
executableArgs
} = argParser.parseArgs();
const [incrementalZipFile, deletionsFile] = incrementalArgs || [];
const [incrementalZipFile, changesFile] = incrementalArgs || [];
const [fullZipFile] = fullZipFileArgs || [];
const [executable] = executableArgs || [];
@ -55,17 +55,56 @@ if (!incrementalZipFile && !fullZipFile) {
process.exit(1);
}
// Do a quick litmus test to prevent deleting everything incorrectly
if (changesFile && !fs.existsSync("base")) {
console.error("The working directory must be set to an " +
"asset folder in order for deleted directories " +
"to be calculated correctly. Abort.");
process.exit(1);
}
const manifest = JSON.parse(fs.readFileSync(manifestFile));
const deleteActions = deletionsFile ? fs.readFileSync(deletionsFile)
const dirsDeleted = new Set();
const specialActions = changesFile ?
fs.readFileSync(changesFile)
.toString()
.trim()
.split("\n").map(file => {
// XXX: This does not delete empty directories. Finding them would
// actually be a substantial amount of work because Git does not
// give us a good way of finding directories that were deleted.
return { action: "delete", target: file };
}) : [];
.split("\n")
.map(line => line.split("\t"))
.map(([mode, target, source]) => {
switch (mode[0]) {
case "D": // Deleted
// Check if the folder exists relative to the working
// directory, and if not, add it to the dirsDeleted list.
// Keep going up the tree to see how many directories were
// deleted.
let dir = path.dirname(target);
while (!dirsDeleted.has(dir) && !fs.existsSync(dir)) {
dirsDeleted.add(dir);
dir = path.dirname(dir);
}
return { action: "delete", target };
case "R": // Renamed
// NOTE: Make sure that the launcher's implementation of
// the move action also creates directories when needed.
return { action: "move", source, target};
default:
return null;
}
})
// Remove ignored file mode changes
.filter(action => action !== null)
// Create actions based on directories to be deleted.
// Always have deeper directories first, to guarantee that deleting
// higher-level directories will succeed.
+ Array.from(dirsDeleted.values())
.sort((a, b) => b.split("/").length - a.split("/").length)
.map(dir => {
return { action: "deleteDir", target: dir };
})
: [];
const urlBase = "https://s3.wasabisys.com/ao-downloads/";
@ -83,7 +122,7 @@ const versionEntry = {
}
] : undefined,
update: incrementalArgs ? [
...deleteActions,
...specialActions,
{
action: "dl",
url: urlBase + encodeURIComponent(path.basename(incrementalZipFile)),

View File

@ -36,16 +36,15 @@ echo "Current tagged version: ${VERSION}"
if [[ -n $ARCHIVE_INCR && -n $LAST_TAGGED_VERSION ]]; then
echo "Incremental archive: ${ARCHIVE_INCR}"
# Get deleted files
export DELETIONS_FILE="deletions.txt"
git log --diff-filter=D --summary ${LAST_TAGGED_VERSION}..HEAD | \
grep "delete mode" | cut -d' ' -f 5- > ${DELETIONS_FILE}
# Get all files
export CHANGES_FILE="changes.txt"
git diff --summary ${LAST_TAGGED_VERSION}..HEAD > ${CHANGES_FILE}
# Get added/modified files
git log --name-only --oneline --diff-filter=d ${LAST_TAGGED_VERSION}..HEAD | \
grep -v -E "^[0-9a-f]{7} " | sort -u | zip ${ARCHIVE_INCR} -@
git diff --name-only --diff-filter=dr ${LAST_TAGGED_VERSION}..HEAD | \
zip ${ARCHIVE_INCR} -@
export ARCHIVE_INCR_ARG="-i ${ARCHIVE_INCR} ${DELETIONS_FILE}"
export ARCHIVE_INCR_ARG="-i ${ARCHIVE_INCR} ${CHANGES_FILE}"
elif [[ -n $ARCHIVE_INCR && -z $LAST_TAGGED_VERSION ]]; then
echo "Incremental archive was requested, but there is no previous version"
fi