Skip to content

Commit a477e60

Browse files
author
Chris Townsend
committed
backends: Add ability to specify different folders depending on backend
Fixes #774
1 parent 4a97074 commit a477e60

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

include/multipass/platform.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2018 Canonical, Ltd.
2+
* Copyright (C) 2017-2019 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -13,8 +13,6 @@
1313
* You should have received a copy of the GNU General Public License
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
16-
* Authored by: Alberto Aguirre <[email protected]>
17-
*
1816
*/
1917

2018
#ifndef MULTIPASS_PLATFORM_H
@@ -34,6 +32,7 @@ namespace platform
3432
{
3533
std::string default_server_address();
3634
VirtualMachineFactory::UPtr vm_backend(const Path& data_dir);
35+
Path backend_specific_dir(const Path& original_path);
3736
logging::Logger::UPtr make_logger(logging::Level level);
3837
UpdatePrompt::UPtr make_update_prompt();
3938
int chown(const char* path, unsigned int uid, unsigned int gid);

src/daemon/daemon.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ auto name_from(const std::string& requested_name, mp::NameGenerator& name_gen, c
193193

194194
std::unordered_map<std::string, mp::VMSpecs> load_db(const mp::Path& data_path, const mp::Path& cache_path)
195195
{
196-
QDir data_dir{data_path};
197-
QDir cache_dir{cache_path};
196+
QDir data_dir{mp::platform::backend_specific_dir(data_path)};
197+
QDir cache_dir{mp::platform::backend_specific_dir(cache_path)};
198198
QFile db_file{data_dir.filePath(instance_db_name)};
199199
auto opened = db_file.open(QIODevice::ReadOnly);
200200
if (!opened)
@@ -1756,7 +1756,7 @@ void mp::Daemon::persist_instances()
17561756
auto key = QString::fromStdString(record.first);
17571757
instance_records_json.insert(key, vm_spec_to_json(record.second));
17581758
}
1759-
QDir data_dir{config->data_directory};
1759+
QDir data_dir{mp::platform::backend_specific_dir(config->data_directory)};
17601760
mp::write_json(instance_records_json, data_dir.filePath(instance_db_name));
17611761
}
17621762

src/daemon/default_vm_image_vault.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <multipass/exceptions/create_image_exception.h>
2222
#include <multipass/logging/log.h>
23+
#include <multipass/path.h>
2324
#include <multipass/platform.h>
2425
#include <multipass/query.h>
2526
#include <multipass/rpc/multipass.grpc.pb.h>
@@ -248,8 +249,8 @@ mp::DefaultVMImageVault::DefaultVMImageVault(std::vector<VMImageHost*> image_hos
248249
mp::Path cache_dir_path, mp::Path data_dir_path, mp::days days_to_expire)
249250
: image_hosts{image_hosts},
250251
url_downloader{downloader},
251-
cache_dir{QDir(cache_dir_path).filePath("vault")},
252-
data_dir{QDir(data_dir_path).filePath("vault")},
252+
cache_dir{QDir(mp::platform::backend_specific_dir(cache_dir_path)).filePath("vault")},
253+
data_dir{QDir(mp::platform::backend_specific_dir(data_dir_path)).filePath("vault")},
253254
instances_dir(data_dir.filePath("instances")),
254255
images_dir(cache_dir.filePath("images")),
255256
days_to_expire{days_to_expire},

src/platform/platform_linux.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2018 Canonical, Ltd.
2+
* Copyright (C) 2017-2019 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -13,8 +13,6 @@
1313
* You should have received a copy of the GNU General Public License
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
16-
* Authored by: Alberto Aguirre <[email protected]>
17-
*
1816
*/
1917

2018
#include <multipass/platform.h>
@@ -61,6 +59,11 @@ mp::VirtualMachineFactory::UPtr mp::platform::vm_backend(const mp::Path& data_di
6159
throw std::runtime_error("Invalid virtualization driver set in the environment");
6260
}
6361

62+
mp::Path mp::platform::backend_specific_dir(const mp::Path& original_path)
63+
{
64+
return original_path;
65+
}
66+
6467
mp::UpdatePrompt::UPtr mp::platform::make_update_prompt()
6568
{
6669
return std::make_unique<DisabledUpdatePrompt>();

0 commit comments

Comments
 (0)