Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 29, 2024
1 parent 8946391 commit 85f8f1a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
28 changes: 23 additions & 5 deletions web/src/components/storage/ProposalSettingsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { _ } from "~/i18n";
import { If, PasswordAndConfirmationInput, Section, Popup } from "~/components/core";
import { Icon } from "~/components/layout";
import { noop } from "~/utils";
import { hasFS } from "~/components/storage/utils";
import { hasFS, isTransactionalSystem } from "~/components/storage/utils";

/**
* @typedef {import ("~/client/storage").ProposalManager.ProposalSettings} ProposalSettings
Expand Down Expand Up @@ -147,7 +147,9 @@ const SnapshotsField = ({
const forcedSnapshots = !configurableSnapshots && hasFS(rootVolume, "Btrfs") && rootVolume.snapshots;

const SnapshotsToggle = () => {
const explanation = _("Uses Btrfs for the root file system allowing to boot to a previous version of the system after configuration changes or software upgrades.");
const explanation = _("Uses Btrfs for the root file system allowing to boot to a previous \
version of the system after configuration changes or software upgrades.");

return (
<>
<Switch
Expand Down Expand Up @@ -312,12 +314,28 @@ export default function ProposalSettingsSection({

const encryption = settings.encryptionPassword !== undefined && settings.encryptionPassword.length > 0;

const transactional = isTransactionalSystem(settings?.volumes || []);

return (
<>
<Section title={_("Settings")}>
<SnapshotsField
settings={settings}
onChange={changeBtrfsSnapshots}
<If
condition={transactional}
then={
<div>
<label>{_("Transactional system")}</label>
<div>
{_("Improve security with an immutable root file system. The system is atomically \
updated allowing to boot to a previous version.")}
</div>
</div>
}
else={
<SnapshotsField
settings={settings}
onChange={changeBtrfsSnapshots}
/>
}
/>
<EncryptionField
password={settings.encryptionPassword || ""}
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/storage/ProposalVolumes.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2022-2023] SUSE LLC
* Copyright (c) [2022-2024] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -34,7 +34,7 @@ import { _ } from "~/i18n";
import { Em, If, Popup, RowActions, Tip } from '~/components/core';
import { Icon } from '~/components/layout';
import { VolumeForm } from '~/components/storage';
import { deviceSize } from '~/components/storage/utils';
import { deviceSize, hasSnapshots, isTransactionalRoot } from '~/components/storage/utils';
import { noop } from "~/utils";

/**
Expand Down Expand Up @@ -200,8 +200,8 @@ const VolumeRow = ({ columns, volume, options, isLoading, onEdit, onDelete }) =>
};

const Details = ({ volume, options }) => {
const hasSnapshots = volume.fsType === "Btrfs" && volume.snapshots;
const transactional = volume.fsType === "Btrfs" && volume.transactional;
const snapshots = hasSnapshots(volume);
const transactional = isTransactionalRoot(volume);

// TRANSLATORS: the filesystem uses a logical volume (LVM)
const text = `${volume.fsType} ${options.lvm ? _("logical volume") : _("partition")}`;
Expand All @@ -215,7 +215,7 @@ const VolumeRow = ({ columns, volume, options, isLoading, onEdit, onDelete }) =>
{/* TRANSLATORS: filesystem flag, it uses an encryption */}
<If condition={options.encryption} then={<Em icon={lockIcon}>{_("encrypted")}</Em>} />
{/* TRANSLATORS: filesystem flag, it allows creating snapshots */}
<If condition={hasSnapshots} then={<Em icon={snapshotsIcon}>{_("with snapshots")}</Em>} />
<If condition={snapshots} then={<Em icon={snapshotsIcon}>{_("with snapshots")}</Em>} />
{/* TRANSLATORS: flag for transactional file system */}
<If condition={transactional} then={<Em icon={transactionalIcon}>{_("transactional")}</Em>} />
</div>
Expand Down
37 changes: 35 additions & 2 deletions web/src/components/storage/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2023] SUSE LLC
* Copyright (c) [2023-2024] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -149,6 +149,36 @@ const hasFS = (volume, fs) => {
return volFS.toLowerCase() === fs.toLocaleLowerCase();
};

/**
* Checks whether the given volume has snapshots.
*
* @param {import(~/clients/storage).Volume} volume
* @returns {boolean}
*/
const hasSnapshots = (volume) => {
return volume.fsType === "Btrfs" && volume.snapshots;
};

/**
* Checks whether the given volume defines a transactional root.
*
* @param {import(~/clients/storage).Volume} volume
* @returns {boolean}
*/
const isTransactionalRoot = (volume) => {
return volume.mountPath === "/" && volume.fsType === "Btrfs" && volume.transactional;
};

/**
* Checks whether the given volumes defines a transactional system.
*
* @param {import(~/clients/storage).Volume[]} volumes
* @returns {boolean}
*/
const isTransactionalSystem = (volumes) => {
return volumes.find(v => isTransactionalRoot(v)) !== undefined;
};

export {
DEFAULT_SIZE_UNIT,
SIZE_METHODS,
Expand All @@ -157,5 +187,8 @@ export {
deviceSize,
parseToBytes,
splitSize,
hasFS
hasFS,
hasSnapshots,
isTransactionalRoot,
isTransactionalSystem
};

0 comments on commit 85f8f1a

Please sign in to comment.