Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- use defines for common values #911

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/installation-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ step2(const string& device, const string& root_prefix, const string& default_sub
string subvol_option = default_subvolume_name;
if (!subvol_option.empty())
subvol_option += "/";
subvol_option += ".snapshots";
subvol_option += SNAPSHOTS_NAME;

mkdir((root_prefix + "/.snapshots").c_str(), 0777);
mkdir((root_prefix + "/" SNAPSHOTS_NAME).c_str(), 0777);

SDir s_dir(root_prefix + "/.snapshots");
SDir s_dir(root_prefix + "/" SNAPSHOTS_NAME);
if (!s_dir.mount(device, "btrfs", 0, "subvol=" + subvol_option))
{
cerr << "mounting .snapshots failed" << endl;
Expand Down
25 changes: 13 additions & 12 deletions snapper/Bcachefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "snapper/File.h"
#include "snapper/Snapper.h"
#include "snapper/SnapperTmpl.h"
#include "snapper/SnapperDefines.h"

#include "snapper/Acls.h"
#include "snapper/Exception.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ namespace snapper

try
{
create_subvolume(subvolume_dir.fd(), ".snapshots");
create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error_with_errno& e)
{
Expand All @@ -90,7 +91,7 @@ namespace snapper
}
}

SFile x(subvolume_dir, ".snapshots");
SFile x(subvolume_dir, SNAPSHOTS_NAME);

#ifdef ENABLE_SELINUX
try
Expand Down Expand Up @@ -119,7 +120,7 @@ namespace snapper

try
{
delete_subvolume(subvolume_dir.fd(), ".snapshots");
delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error& e)
{
Expand All @@ -132,8 +133,8 @@ namespace snapper
string
Bcachefs::snapshotDir(unsigned int num) const
{
return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
"/snapshot";
return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
"/" SNAPSHOT_NAME;
}


Expand Down Expand Up @@ -161,7 +162,7 @@ namespace snapper
Bcachefs::openInfosDir() const
{
SDir subvolume_dir = openSubvolumeDir();
SDir infos_dir(subvolume_dir, ".snapshots");
SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);

struct stat stat;
if (infos_dir.stat(&stat) != 0)
Expand Down Expand Up @@ -200,7 +201,7 @@ namespace snapper
Bcachefs::openSnapshotDir(unsigned int num) const
{
SDir info_dir = openInfoDir(num);
SDir snapshot_dir(info_dir, "snapshot");
SDir snapshot_dir(info_dir, SNAPSHOT_NAME);

return snapshot_dir;
}
Expand All @@ -218,9 +219,9 @@ namespace snapper
try
{
if (empty)
create_subvolume(info_dir.fd(), "snapshot");
create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
else
create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
}
catch (const runtime_error& e)
{
Expand All @@ -235,7 +236,7 @@ namespace snapper

try
{
create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
}
catch (const runtime_error& e)
{
Expand All @@ -253,7 +254,7 @@ namespace snapper

try
{
delete_subvolume(info_dir.fd(), "snapshot");
delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);
}
catch (const runtime_error& e)
{
Expand Down Expand Up @@ -306,7 +307,7 @@ namespace snapper
SDir info_dir = openInfoDir(num);

struct stat stat;
int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
return r == 0 && is_subvolume(stat);
}
catch (const IOErrorException& e)
Expand Down
36 changes: 18 additions & 18 deletions snapper/Btrfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace snapper

try
{
create_subvolume(subvolume_dir.fd(), ".snapshots");
create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error_with_errno& e)
{
Expand All @@ -151,7 +151,7 @@ namespace snapper
}
}

SFile x(subvolume_dir, ".snapshots");
SFile x(subvolume_dir, SNAPSHOTS_NAME);
#ifdef ENABLE_SELINUX
try
{
Expand Down Expand Up @@ -179,15 +179,15 @@ namespace snapper
#ifdef ENABLE_ROLLBACK
if (subvolume == "/")
{
subvolume_dir.umount(".snapshots");
subvolume_dir.umount(SNAPSHOTS_NAME);

removeFromFstab();
}
#endif

try
{
delete_subvolume(subvolume_dir.fd(), ".snapshots");
delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error& e)
{
Expand Down Expand Up @@ -238,8 +238,8 @@ namespace snapper
string
Btrfs::snapshotDir(unsigned int num) const
{
return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
"/snapshot";
return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
"/" SNAPSHOT_NAME;
}


Expand Down Expand Up @@ -267,7 +267,7 @@ namespace snapper
Btrfs::openInfosDir() const
{
SDir subvolume_dir = openSubvolumeDir();
SDir infos_dir(subvolume_dir, ".snapshots");
SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);

struct stat stat;
if (infos_dir.stat(&stat) != 0)
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace snapper
Btrfs::openSnapshotDir(unsigned int num) const
{
SDir info_dir = openInfoDir(num);
SDir snapshot_dir(info_dir, "snapshot");
SDir snapshot_dir(info_dir, SNAPSHOT_NAME);

return snapshot_dir;
}
Expand All @@ -331,9 +331,9 @@ namespace snapper
try
{
if (empty)
create_subvolume(info_dir.fd(), "snapshot");
create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
else
create_snapshot(subvolume_dir.fd(), info_dir.fd(), "snapshot", read_only,
create_snapshot(subvolume_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
Expand All @@ -349,7 +349,7 @@ namespace snapper

try
{
create_snapshot(snapshot_dir.fd(), info_dir.fd(), "snapshot", read_only,
create_snapshot(snapshot_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace snapper

try
{
create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), "snapshot", read_only,
create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
Expand Down Expand Up @@ -419,15 +419,15 @@ namespace snapper
subvolid_t subvolid = get_id(openSnapshotDir(num).fd());
#endif

delete_subvolume(info_dir.fd(), "snapshot");
delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);

#if defined(HAVE_LIBBTRFS) || defined(HAVE_LIBBTRFSUTIL)
deleted_subvolids.push_back(subvolid);
#endif
}
catch (const runtime_error& e)
{
y2err("delete snapshot " << info_dir.fullname() << "/snapshot failed, " << e.what());
y2err("delete snapshot " << info_dir.fullname() << "/" SNAPSHOT_NAME " failed, " << e.what());
SN_THROW(DeleteSnapshotFailedException());
}
}
Expand Down Expand Up @@ -476,7 +476,7 @@ namespace snapper
SDir info_dir = openInfoDir(num);

struct stat stat;
int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
return r == 0 && is_subvolume(stat);
}
catch (const IOErrorException& e)
Expand Down Expand Up @@ -1614,7 +1614,7 @@ namespace snapper
string subvol_option = default_subvolume_name;
if (!subvol_option.empty())
subvol_option += "/";
subvol_option += ".snapshots";
subvol_option += SNAPSHOTS_NAME;

MntTable mnt_table(root_prefix);
mnt_table.parse_fstab();
Expand All @@ -1627,7 +1627,7 @@ namespace snapper
if (!snapshots)
throw runtime_error("mnt_copy_fs failed");

mnt_fs_set_target(snapshots, "/.snapshots");
mnt_fs_set_target(snapshots, "/" SNAPSHOTS_NAME);

char* options = mnt_fs_strdup_options(snapshots);
mnt_optstr_remove_option(&options, "defaults");
Expand All @@ -1646,7 +1646,7 @@ namespace snapper
MntTable mnt_table(root_prefix);
mnt_table.parse_fstab();

string mountpoint = (subvolume == "/" ? "" : subvolume) + "/.snapshots";
string mountpoint = (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME;
libmnt_fs* snapshots = mnt_table.find_target(mountpoint, MNT_ITER_FORWARD);
if (!snapshots)
return;
Expand Down
3 changes: 2 additions & 1 deletion snapper/Compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "snapper/Exception.h"
#include "snapper/XAttributes.h"
#include "snapper/Acls.h"
#include "snapper/SnapperDefines.h"


namespace snapper
Expand Down Expand Up @@ -259,7 +260,7 @@ namespace snapper
bool
filter(const string& name)
{
if (name == "/.snapshots")
if (name == "/" SNAPSHOTS_NAME)
return true;

return false;
Expand Down
14 changes: 7 additions & 7 deletions snapper/Ext4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ namespace snapper
void
Ext4::createConfig() const
{
int r1 = mkdir((subvolume + "/.snapshots").c_str(), 0700);
int r1 = mkdir((subvolume + "/" SNAPSHOTS_NAME).c_str(), 0700);
if (r1 == 0)
{
SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/.snapshots" });
SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/" SNAPSHOTS_NAME });
if (cmd1.retcode() != 0)
throw CreateConfigFailedException("chattr failed");
}
Expand All @@ -101,10 +101,10 @@ namespace snapper
throw CreateConfigFailedException("mkdir failed");
}

int r2 = mkdir((subvolume + "/.snapshots/.info").c_str(), 0700);
int r2 = mkdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str(), 0700);
if (r2 == 0)
{
SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/.snapshots/.info" });
SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/" SNAPSHOTS_NAME "/.info" });
if (cmd2.retcode() != 0)
throw CreateConfigFailedException("chattr failed");
}
Expand All @@ -119,14 +119,14 @@ namespace snapper
void
Ext4::deleteConfig() const
{
int r1 = rmdir((subvolume + "/.snapshots/.info").c_str());
int r1 = rmdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str());
if (r1 != 0)
{
y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
throw DeleteConfigFailedException("rmdir failed");
}

int r2 = rmdir((subvolume + "/.snapshots").c_str());
int r2 = rmdir((subvolume + "/" SNAPSHOTS_NAME).c_str());
if (r2 != 0)
{
y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
Expand All @@ -145,7 +145,7 @@ namespace snapper
string
Ext4::snapshotFile(unsigned int num) const
{
return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num);
return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num);
}


Expand Down
Loading
Loading