// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using Duplicati.Library.Common.IO;
namespace Duplicati.Library.Snapshots
{
///
/// Handler for providing a snapshot like access to files and folders
///
public sealed class NoSnapshotLinux : SnapshotBase
{
///
/// Returns the symlink target if the entry is a symlink, and null otherwise
///
/// The file or folder to examine
/// The symlink target
public override string GetSymlinkTarget(string localPath)
{
return SystemIO.IO_SYS.GetSymlinkTarget(localPath);
}
///
/// Gets the metadata for the given file or folder
///
/// The metadata for the given file or folder
/// The file or folder to examine
/// A flag indicating if the target is a symlink
/// A flag indicating if a symlink should be followed
public override Dictionary GetMetadata(string localPath, bool isSymlink, bool followSymlink)
{
return SystemIO.IO_SYS.GetMetadata(localPath, isSymlink, followSymlink);
}
///
/// Gets a value indicating if the path points to a block device
///
/// true if this instance is a block device; otherwise, false.
/// The file or folder to examine
public override bool IsBlockDevice(string localPath)
{
var n = PosixFile.GetFileType(SystemIOLinux.NormalizePath(localPath));
switch (n)
{
case PosixFile.FileType.Directory:
case PosixFile.FileType.Symlink:
case PosixFile.FileType.File:
return false;
default:
return true;
}
}
///
/// Gets a unique hardlink target ID
///
/// The hardlink ID
/// The file or folder to examine
public override string HardlinkTargetID(string localPath)
{
var normalizePath = SystemIOLinux.NormalizePath(localPath);
return PosixFile.GetHardlinkCount(normalizePath) <= 1
? null
: PosixFile.GetInodeTargetID(normalizePath);
}
///
public override string ConvertToLocalPath(string snapshotPath)
{
return snapshotPath;
}
///
public override string ConvertToSnapshotPath(string localPath)
{
return SystemIOLinux.NormalizePath(localPath);
}
}
}