From f29ce7db058d36c8581004d951c4cfdcb8e65578 Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Wed, 29 Dec 2021 15:56:29 +0100 Subject: [PATCH] Small change in bdb_get_file_record() This is needed, because when Plugin update it's file attributes during backup, two file records for the same JobId are generated. To display only the newest one (the one having the most recent attributes) in the restore menu, we need to take with the highest DeltaSeq value. --- bacula/src/cats/sql_get.c | 2 +- bacula/src/cats/sql_list.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index c81657ed9..0b1697fbb 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -126,7 +126,7 @@ bool BDB::bdb_get_file_record(JCR *jcr, JOB_DBR *jr, FILE_DBR *fdbr) if (fdbr->PathId && fdbr->Filename) { Mmsg(cmd, "SELECT FileId, LStat, MD5, FileIndex FROM File WHERE File.JobId=%s AND File.PathId=%s AND " - "File.Filename='%s'", + "File.Filename='%s' ORDER BY DeltaSeq DESC LIMIT 1", edit_int64(fdbr->JobId, ed1), edit_int64(fdbr->PathId, ed2), fdbr->Filename); diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 8b5985bec..2c2173781 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -1067,6 +1067,9 @@ void BDB::bdb_list_files_for_job(JCR *jcr, JobId_t jobid, int deleted, DB_LIST_H ") AS F JOIN Path ON (Path.PathId=F.PathId) %s %s", edit_int64(jobid, ed1), opt, ed1, join, where); } else { + /* Note: For some files with attributes update may be listed twice here. + * We may consider adding 'DISTICT' to the query, but since it could + * make query much longer it would be nice to handle it in some different way. */ Mmsg(cmd, "SELECT Path.Path||F.Filename AS Filename " "FROM (SELECT PathId, Filename, JobId FROM File WHERE JobId=%s %s" "UNION ALL " -- 2.47.3