• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 2130748468

30 Oct 2025 09:49PM UTC coverage: 79.832% (-0.05%) from 79.881%
2130748468

push

gitlab-ci

web-flow
Merge pull request #1840 from danielskinstad/space-function

chore: common/io function to get available space

0 of 6 new or added lines in 1 file covered. (0.0%)

7810 of 9783 relevant lines covered (79.83%)

14025.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/src/common/io/platform/c++17/io.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/io.hpp>
16

17
#include <filesystem>
18

19
namespace mender {
20
namespace common {
21
namespace io {
22

23
namespace error = mender::common::error;
24
namespace expected = mender::common::expected;
25

26
namespace fs = std::filesystem;
27

28
expected::ExpectedSize FileSize(const string &path) {
54✔
29
        error_code ec;
54✔
30
        auto size = fs::file_size(fs::path(path), ec);
54✔
31
        if (ec) {
54✔
32
                return expected::unexpected(
×
33
                        error::Error(ec.default_error_condition(), "Could not determine file size of " + path));
×
34
        }
35
        return size;
36
}
37

NEW
38
expected::ExpectedUintMax GetAvailableSpace(const string &path) {
×
39
        try {
NEW
40
                fs::space_info space_info = fs::space(path);
×
41
                return space_info.available;
NEW
42
        } catch (const fs::filesystem_error &e) {
×
NEW
43
                return expected::unexpected(error::Error(
×
NEW
44
                        e.code().default_error_condition(),
×
NEW
45
                        "Failed to get disk space for path '" + path + "': " + e.what()));
×
46
        }
47
}
48

49
} // namespace io
50
} // namespace common
51
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc