Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- wipe_daemon.lua
- local keepFile = "wipe_daemon.lua" -- The file that survives
- local intervalDays = 10 -- Days between wipes
- local timeFile = ".last_wipe_time" -- Hidden file to track last wipe
- local checkIntervalMinutes = 30 -- How often to check (in minutes)
- -- Current UTC time in ms
- local function currentTime()
- return os.epoch("utc")
- end
- -- Should we wipe?
- local function shouldWipe()
- if not fs.exists(timeFile) then
- return true
- end
- local file = fs.open(timeFile, "r")
- local lastTime = tonumber(file.readAll())
- file.close()
- local elapsed = (currentTime() - lastTime) / (1000 * 60 * 60 * 24)
- return elapsed >= intervalDays
- end
- -- Record last wipe time
- local function recordWipeTime()
- local file = fs.open(timeFile, "w")
- file.write(tostring(currentTime()))
- file.close()
- end
- -- Wipe all files except the keeper and the time file
- local function wipeFiles()
- for _, name in ipairs(fs.list("/")) do
- if name ~= keepFile and name ~= timeFile then
- fs.delete(name)
- end
- end
- recordWipeTime()
- end
- -- Main loop
- while true do
- if shouldWipe() then
- wipeFiles()
- end
- sleep(checkIntervalMinutes * 60) -- Wait before checking again
- end
Advertisement
Add Comment
Please, Sign In to add comment