1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2019-2020 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 
24 #include "stored/autochanger_resource.h"
25 #include "lib/alist.h"
26 #include "stored/device_resource.h"
27 #include "stored/stored_globals.h"
28 
29 namespace storagedaemon {
30 
AutochangerResource()31 AutochangerResource::AutochangerResource()
32     : BareosResource()
33     , device_resources(nullptr)
34     , changer_name(nullptr)
35     , changer_command(nullptr)
36 {
37   return;
38 }
39 
operator =(const AutochangerResource & rhs)40 AutochangerResource& AutochangerResource::operator=(
41     const AutochangerResource& rhs)
42 {
43   BareosResource::operator=(rhs);
44   device_resources = rhs.device_resources;
45   changer_name = rhs.changer_name;
46   changer_command = rhs.changer_command;
47   changer_lock = rhs.changer_lock;
48   return *this;
49 }
50 
PrintConfig(OutputFormatterResource & send,const ConfigurationParser &,bool hide_sensitive_data,bool verbose)51 bool AutochangerResource::PrintConfig(OutputFormatterResource& send,
52                                       const ConfigurationParser&,
53                                       bool hide_sensitive_data,
54                                       bool verbose)
55 {
56   alist* original_alist = device_resources;
57   alist* temp_alist = new alist(original_alist->size(), not_owned_by_alist);
58   DeviceResource* device_resource = nullptr;
59   foreach_alist (device_resource, original_alist) {
60     if (device_resource->multiplied_device_resource) {
61       if (device_resource->multiplied_device_resource == device_resource) {
62         DeviceResource* d = new DeviceResource(*device_resource);
63         d->MultipliedDeviceRestoreBaseName();
64         temp_alist->append(d);
65       }
66     } else {
67       DeviceResource* d = new DeviceResource(*device_resource);
68       temp_alist->append(d);
69     }
70   }
71   device_resources = temp_alist;
72   BareosResource::PrintConfig(send, *my_config, hide_sensitive_data, verbose);
73   device_resources = original_alist;
74   foreach_alist (device_resource, temp_alist) {
75     delete device_resource;
76   }
77   delete temp_alist;
78   return true;
79 }
80 
81 } /* namespace storagedaemon */
82