szabodanika / microbin

A secure, configurable file-sharing and URL shortening web app written in Rust.
https://microbin.eu
BSD 3-Clause "New" or "Revised" License
2.63k stars 160 forks source link

[Bug] Never expiring pastas deleted immediately #11

Closed DaviDeMeo closed 2 years ago

DaviDeMeo commented 2 years ago

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" https://github.com/szabodanika/microbin/blob/9e4940eb449e2f0d9da54ea37719d12e611a0ff4/src/main.rs#L392-L402

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 commented 2 years ago

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!