// Copyright (C) 2025, 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. #nullable enable using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using Duplicati.Library.Interface; namespace Duplicati.Library.Snapshots { /// /// An interface for a snapshot implementation /// public interface ISnapshotService : IDisposable { /// /// Gets the source entries /// IEnumerable SourceEntries { get; } /// /// Enumerates the root source files and folders /// /// The source files and folders IEnumerable EnumerateFilesystemEntries(); /// /// Enumerates the files and folders in a given folder /// /// The parent folder to enumerate /// The files and folders in the parent folder IEnumerable EnumerateFilesystemEntries(ISourceProviderEntry parent); /// /// Gets a filesystem entry for a given path /// /// The path to get /// True if the path is a folder /// The filesystem entry ISourceProviderEntry? GetFilesystemEntry(string path, bool isFolder); /// /// Gets the last write time of a given file in UTC /// /// The full path to the file in non-snapshot format /// The last write time of the file DateTime GetLastWriteTimeUtc(string localPath); /// /// Gets the last write time of a given file in UTC /// /// The full path to the file in non-snapshot format /// The last write time of the file DateTime GetCreationTimeUtc(string localPath); /// /// Opens a file for reading /// /// The full path to the file in non-snapshot format /// An open filestream that can be read and seeked Stream OpenRead(string localPath); /// /// Opens a file for reading /// /// The full path to the file in non-snapshot format /// A token that can be used to cancel the operation /// An open filestream that can be read and seeked Task OpenReadAsync(string localPath, CancellationToken cancellationToken); /// /// Returns the size of a file /// /// The full path to the file in non-snapshot format /// The length of the file long GetFileSize(string localPath); /// /// Returns the symlink target if the entry is a symlink, and null otherwise /// /// The file or folder to examine /// The symlink target string GetSymlinkTarget(string localPath); /// /// Gets the attributes for the given file or folder /// /// The file attributes /// The file or folder to examine FileAttributes GetAttributes(string 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 Dictionary GetMetadata(string localPath, bool isSymlink); /// /// 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 bool IsBlockDevice(string localPath); /// /// Gets a unique hardlink target ID /// /// The hardlink ID /// The file or folder to examine string? HardlinkTargetID(string localPath); /// /// Converts a snapshot path to a local path /// /// The snapshot-local path /// The local path string ConvertToLocalPath(string snapshotPath); /// /// Converts a local path to a snapshot-local path /// /// The local path /// The snapshot path string ConvertToSnapshotPath(string localPath); /// /// Tests if a file exists in the snapshot /// /// The local path /// True if file exists, false otherwise bool FileExists(string localFilePath); /// /// Tests if a folder exists in the snapshot /// /// The local path /// True if folder exists, false otherwise bool DirectoryExists(string localFolderPath); } }