Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Never expiring pastas deleted immediately #11

Closed
DaviDeMeo opened this issue May 9, 2022 · 1 comment
Closed

[Bug] Never expiring pastas deleted immediately #11

DaviDeMeo opened this issue May 9, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@DaviDeMeo
Copy link

This code get called immediately when the page redirect to the newly created pasta
and the check at line 394 will always be true for pasta with expiration of "never"

microbin/src/main.rs

Lines 392 to 402 in 9e4940e

pastas.retain(|p| {
// delete the files too
if p.expiration < timenow {
// remove the file itself
fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file));
// and remove the containing directory
fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals()));
};
p.expiration == 0 || p.expiration > timenow
});

this should fix it and do one less comparison

    pastas.retain(|p| {
        // expiration is `never` or not reached
        if p.expiration == 0 || p.expiration > timenow {
            // keep
            true
        } else {
            // remove the file itself
            fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file));
            // and remove the containing directory
            fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals()));
            // remove
            false
        }
    });
@szabodanika szabodanika added the bug Something isn't working label May 9, 2022
szabodanika added a commit that referenced this issue May 9, 2022
Also changed expiration date to show "Never" instead of unix epoch in the pasta list, and renamed a few variables in animalnumbers.rs to make the function more readable.
@szabodanika
Copy link
Owner

It works fine for me with your change, can you give it a try? You can also deploy it on docker now B-).

Thanks for your help @DaviDeMeo, it is very appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants