From c4bb3494172f98ed9384c15402486e37835809b3 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 27 May 2018 11:38:39 +0200 Subject: [PATCH] Fix bug #2343 where truncate of explicit Volume name truncates non-purged volumes --- bacula/src/dird/ua_purge.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index 5bffaeb6fa..6d85b91950 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -705,6 +705,11 @@ int truncate_cmd(UAContext *ua, const char *cmd) mr.clear(); mr.MediaId = results[i]; if (db_get_media_record(ua->jcr, ua->db, &mr)) { + if (strcasecmp(mr.VolStatus, "Purged") != 0) { + ua->send_msg(_("Truncate Volume \"%s\" skipped. Status is \"%s\", but must be \"Purged\".\n"), + mr.VolumeName, mr.VolStatus); + continue; + } if (drive < 0) { STORE *store = (STORE*)GetResWithName(R_STORAGE, storage); drive = get_storage_drive(ua, store); @@ -714,7 +719,7 @@ int truncate_cmd(UAContext *ua, const char *cmd) if (pr.PoolId == 0) { pr.PoolId = mr.PoolId; if (!db_get_pool_record(ua->jcr, ua->db, &pr)) { - return 1; + goto bail_out; /* free allocated memory */ } } if (strcasecmp("truncate", action) == 0) { -- 2.39.5