Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/sessionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ SessionManager::SessionManager(Settings *settings, QObject *parent)
// save path returns early without arming the timer. Without this, that
// content only flushes at aboutToQuit — and is lost if the app is killed first.
connect(m_settings, &Settings::scrollbackPersistenceChanged, this, [this]() {
if (!m_settings->scrollbackPersistence() || !m_sessionsLoaded)
if (!m_settings->scrollbackPersistence()) {
// Purge all scrollback files immediately. Not gated on m_sessionsLoaded:
// files exist on disk regardless of session state (privacy expectation).
cleanupScrollbackFiles(true);
return;
}
if (!m_sessionsLoaded)
return;
// Enabled — re-arm dirty sessions + schedule a save.
bool any = false;
for (SessionInfo &info : m_sessions) {
if (info.view) {
Expand All @@ -131,6 +138,14 @@ SessionManager::SessionManager(Settings *settings, QObject *parent)
scheduleScrollbackSave();
});

connect(m_settings, &Settings::scrollbackRetentionDaysChanged, this, [this]() {
// Reducing retention should purge now-overage files immediately.
// No-op when persistence is off (the disable handler already purged everything).
if (!m_settings->scrollbackPersistence())
return;
cleanupScrollbackFiles(); // mtime-gated
});

// Save sessions early on app quit — before QML engine destruction kills
// the terminal views (and their shells), which would make /proc/<pid>/cwd
// unreadable.
Expand Down Expand Up @@ -1043,7 +1058,7 @@ void SessionManager::saveScrollbackIncremental(bool force)
scheduleScrollbackSave();
}

void SessionManager::cleanupScrollbackFiles()
void SessionManager::cleanupScrollbackFiles(bool purgeAll)
{
int retentionDays = m_settings->scrollbackRetentionDays();
QDir dir(scrollbackDir());
Expand All @@ -1055,7 +1070,7 @@ void SessionManager::cleanupScrollbackFiles()
for (const QFileInfo &fi : files) {
if (fi.fileName().startsWith(QStringLiteral("session_"))) {
if (fi.fileName().endsWith(QStringLiteral(".vt"))) {
if (fi.lastModified() < cutoff)
if (purgeAll || fi.lastModified() < cutoff)
QFile::remove(fi.absoluteFilePath());
} else {
// Orphaned QSaveFile temp file from a crash during write.
Expand Down
2 changes: 1 addition & 1 deletion src/sessionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SessionManager : public QObject
// Scrollback persistence
void saveScrollbackIncremental(bool force = false);
void saveSessionScrollback(SessionInfo &info);
void cleanupScrollbackFiles();
void cleanupScrollbackFiles(bool purgeAll = false);
QString scrollbackDir() const;
QString scrollbackFilePath(int sessionId) const;

Expand Down
Loading