/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2018-2025] SUSE LLC
+ * Copyright (c) [2018-2026] SUSE LLC
*
* All Rights Reserved.
*
#include <cstdlib>
#include <cassert>
#include <algorithm>
+#include <regex>
#include "snapper/FileUtils.h"
#include "snapper/AppUtil.h"
}
- static bool
- all_entries(unsigned char type, const char* name)
+ bool
+ SDir::all_entries(unsigned char type, const char* name)
{
return true;
}
+ bool
+ SDir::number_entries(unsigned char type, const char* name)
+ {
+ // Snapshot '0' is internal and not saved on disks. So simply ignore directories
+ // starting with '0'.
+
+ static const regex rx_num("[1-9][0-9]*", regex::extended);
+
+ return regex_match(name, rx_num);
+ }
+
+
vector<string>
SDir::entries() const
{
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2020-2025] SUSE LLC
+ * Copyright (c) [2020-2026] SUSE LLC
*
* All Rights Reserved.
*
// Type is not supported by all file system types, see readdir(3).
typedef std::function<bool(unsigned char type, const char* name)> entries_pred_t;
+ static bool all_entries(unsigned char type, const char* name);
+ static bool number_entries(unsigned char type, const char* name);
+
// The order of the result of the entries functions is undefined.
vector<string> entries() const;
vector<string> entries(entries_pred_t pred) const;
}
}
+ // Since we want all-time unique snapshot numbers there might be empty
+ // directories.
+
+ SDir infos_dir = snapper->openInfosDir();
+
+ for (const string& tmp : infos_dir.entries(SDir::number_entries))
+ infos_dir.rmdir(tmp);
+
try
{
snapper->getFilesystem()->deleteConfig();
#include <fcntl.h>
#include <cerrno>
#include <cstring>
-#include <regex>
#include "snapper/Snapshot.h"
#include "snapper/Snapper.h"
namespace snapper
{
using std::list;
- using std::regex;
std::ostream& operator<<(std::ostream& s, const Snapshot& snapshot)
Snapshots::~Snapshots() = default;
- static bool
- number_entries(unsigned char type, const char* name)
- {
- // Snapshot '0' is internal and not saved on disks. So simply ignore directories
- // starting with '0'.
-
- static const regex rx_num("[1-9][0-9]*", regex::extended);
-
- return regex_match(name, rx_num);
- }
-
-
void
Snapshots::read()
{
SDir infos_dir = snapper->openInfosDir();
- for (const string& info : infos_dir.entries(number_entries))
+ for (const string& info : infos_dir.entries(SDir::number_entries))
{
try
{
// Numbers of directories (and files) found in infos-dir.
vector<unsigned int> nums;
- for (const string& tmp : infos_dir.entries(number_entries))
+ for (const string& tmp : infos_dir.entries(SDir::number_entries))
nums.push_back(stoi(tmp));
// Set num to next available free number. All entries should also be included in