AppImageUpdate icon indicating copy to clipboard operation
AppImageUpdate copied to clipboard

Fix overwrite+remove deleting the wrong file on relative path.

Open EXio4 opened this issue 1 year ago • 1 comments

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:

  1. constructor, when the file needs to be overwritten
  2. populatePathToLocalFileFromZSyncFile
  3. 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 🫡

EXio4 avatar Aug 18 '24 17:08 EXio4

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.

Samueru-sama avatar Aug 18 '24 17:08 Samueru-sama

Thanks!

TheAssassin avatar Sep 04 '24 21:09 TheAssassin