Giter VIP home page Giter VIP logo

Comments (8)

yzj578492228 avatar yzj578492228 commented on June 12, 2024

from update4j.

mordechaim avatar mordechaim commented on June 12, 2024

Hello, thanks for your kind words.

In a typical case where a single client hasn't updated across a few versions the solution is simply to use it cached (offline) version of their current config as the delete source.

The deleteOldFiles wasn't designed to delete arbitrary files, but instead focuses on files left over from old versions. Being that the user did not update, those middle version files aren't even present there.

Is there a case where this doesn't work for you?

from update4j.

Dustinhoefer avatar Dustinhoefer commented on June 12, 2024

Do you have a code example for using the cached offline version of their config file? That would pretty much do what I would like it to :)
Deletion of other, unknown files would only be a plus point, which is not that important right now

from update4j.

mordechaim avatar mordechaim commented on June 12, 2024

The default bootstrap does just this

if (Files.exists(zip)) {
try {
Archive archive = Archive.read(zip);
Configuration oldConfig = null;
Configuration newConfig = archive.getConfiguration();
try (FileSystem fs = archive.openConnection()) {
Path oldPath = fs.getPath(OLD_CONFIG);
if (Files.exists(oldPath)) {
try (BufferedReader in = Files.newBufferedReader(oldPath)) {
oldConfig = Configuration.read(in);
}
}
}
archive.install();
newConfig.deleteOldFiles(oldConfig);
} catch (Exception e) {
e.printStackTrace();
}

In general, you would want to have the config saved locally so if the user is offline they can still start the application. Unless if you only use update4j for updating and not for launching, in which case caching isn't important at all.

from update4j.

Dustinhoefer avatar Dustinhoefer commented on June 12, 2024

Thank you again for your help!
Unfortunately, I am not able to locate the config.old file on my system.

This is what I am doing right now, I added some code from the DefaultBootstrap. Any Idea why there is no config.old file?

        InputStreamReader in = new InputStreamReader(connection.getInputStream());
        Configuration config = Configuration.read(in);
        
        if (config.requiresUpdate()) {
            Path path = Paths.get(System.getProperty("user.home") + "/update.zip");
            ArchiveUpdateOptions archiveOptions = UpdateOptions.archive(path);
            config.update(archiveOptions);
            Archive archive = Archive.read(System.getProperty("user.home") + "/update.zip");
            Configuration oldConfig = null;
        
            try (FileSystem fs = archive.openConnection()) {
	            Path oldPath = fs.getPath("config.old");
	            if (Files.exists(oldPath)) {
		            try (BufferedReader in2 = Files.newBufferedReader(oldPath)) {
			            oldConfig = Configuration.read(in2);
		            }
	            }
            }
        
            archive.install();
            config.deleteOldFiles(oldConfig);
        }
        
        config.launch();

from update4j.

mordechaim avatar mordechaim commented on June 12, 2024

This isn't part of the default archive format, but added by the default bootstrap

BufferedWriter out = Files.newBufferedWriter(fs.getPath(OLD_CONFIG))) {

This was left as part of userland setup being unopinionated where and how to keep configs between updates.

from update4j.

Dustinhoefer avatar Dustinhoefer commented on June 12, 2024

facepalm
So basically after the first update the local config is created. For all further updates, the config is read and updated.
Thank you so much! Hopefuly I won't have to bother you again for some time ;)

from update4j.

mordechaim avatar mordechaim commented on June 12, 2024

Glad I could help!

from update4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.