Fix overwrite+remove deleting the wrong file on relative path.
Fixes #234
The issue seems to be happening due to:
auto oldFilePath = pathToOldAppImage(pathToAppImage.value(), newFilePath);
checking in pathToOldAppImage if the paths are [trivially] equal with a == before, but newFilePath is gathered through pathToNewFile, which gets the data from the zSyncClient object:
bool Updater::pathToNewFile(std::string& path) const {
// only available update method is via ZSync
if (d->zSyncClient)
return d->zSyncClient->pathToNewFile(path);
return false;
}
which internally calls applyCwdToPathToLocalFile, which one of the 3 places where pathToLocalFile is modified:
- constructor, when the file needs to be overwritten
- populatePathToLocalFileFromZSyncFile
- applyCwdToPathToLocalFile
void applyCwdToPathToLocalFile() {
if (strncmp(pathToLocalFile.c_str(), "/", 1) == 0)
return;
auto oldPath = pathToLocalFile;
pathToLocalFile = cwd;
if (!endsWith(pathToLocalFile, "/"))
pathToLocalFile += "/";
pathToLocalFile += oldPath;
}
which will make relative paths absolute, and keep absolute paths 100% equal
I haven't touched this codebase ever, so I'm just going based off vibes for the solution, if there's a better place to put to abspath - to keep the change minimal, that could likely be better, from what I can tell there's quite a few places in updater.cpp where the paths are normalized, like Updater::restoreOriginalFile and Updater::copyPermissionsToNewFile 😅
I'm not using Linux - so @Samueru-sama has been testing the code 🫡
This might also fix #174 however I wasn't able to replicate that issue exactly during testing, by that I mean with only with the -r flag instead of -Or.
This PR does indeed fix the issue with -Or though.
Thanks!