From 53b94a8f5716e2b0dd207360d8ee2ca74c954b11 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Wed, 23 Apr 2025 13:38:03 +0200 Subject: [PATCH] Add async methods to `IFileType` (#19116) * Add GetChecksumStreamAsync and GetLengthAsync * Obsolete CanSetPhysical, Set and GetVirtualPath * Updated obsolete messages to reference Umbraco 18 --------- Co-authored-by: Andy Butland --- src/Umbraco.Core/Deploy/IFileType.cs | 48 +++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Core/Deploy/IFileType.cs b/src/Umbraco.Core/Deploy/IFileType.cs index f8fa5ba92d..0d65ad3b06 100644 --- a/src/Umbraco.Core/Deploy/IFileType.cs +++ b/src/Umbraco.Core/Deploy/IFileType.cs @@ -11,17 +11,18 @@ public interface IFileType /// /// true if the file can be set using a physical path; otherwise, false. /// + [Obsolete("An interface should not expose implementation details. Scheduled for removal in Umbraco 18.")] bool CanSetPhysical { get; } /// - /// Gets the stream as an asynchronous operation. + /// Gets the stream in an asynchronous operation. /// /// The UDI. /// The cancellation token. /// - /// The task object representing the asynchronous operation. + /// The task object representing the asynchronous operation. The task result contains the stream. /// - Task GetStreamAsync(StringUdi udi, CancellationToken token); + Task GetStreamAsync(StringUdi udi, CancellationToken token); // TODO: Rename token to cancellationToken and add default value /// /// Gets the checksum stream. @@ -30,8 +31,22 @@ public interface IFileType /// /// The checksum stream. /// + [Obsolete("Use GetChecksumStreamAsync() instead. Scheduled for removal in Umbraco 18.")] Stream GetChecksumStream(StringUdi udi); + /// + /// Gets the checksum stream in an asynchronous operation. + /// + /// The UDI. + /// The cancellation token. + /// + /// The task object representing the asynchronous operation. The task result contains the checksum stream. + /// + Task GetChecksumStreamAsync(StringUdi udi, CancellationToken cancellationToken = default) +#pragma warning disable CS0618 // Type or member is obsolete + => Task.FromResult(GetChecksumStream(udi)); +#pragma warning restore CS0618 // Type or member is obsolete + /// /// Gets the file length in bytes or -1 if not found. /// @@ -39,8 +54,22 @@ public interface IFileType /// /// The file length in bytes or -1 if not found. /// + [Obsolete("Use GetLengthAsync() instead. Scheduled for removal in Umbraco 18.")] long GetLength(StringUdi udi); + /// + /// Gets the file length in bytes or -1 if not found in an asynchronous operation. + /// + /// The UDI. + /// The cancellation token. + /// + /// The task object representing the asynchronous operation. The task result contains the file length in bytes or -1 if not found. + /// + Task GetLengthAsync(StringUdi udi, CancellationToken cancellationToken = default) +#pragma warning disable CS0618 // Type or member is obsolete + => Task.FromResult(GetLength(udi)); +#pragma warning restore CS0618 // Type or member is obsolete + /// /// Sets the stream as an asynchronous operation. /// @@ -50,7 +79,7 @@ public interface IFileType /// /// The task object representing the asynchronous operation. /// - Task SetStreamAsync(StringUdi udi, Stream stream, CancellationToken token); + Task SetStreamAsync(StringUdi udi, Stream stream, CancellationToken token); // TODO: Rename token to cancellationToken and add default value /// /// Sets the physical path of the file. @@ -58,20 +87,16 @@ public interface IFileType /// The UDI. /// The physical path. /// If set to true copies the file instead of moving. + [Obsolete("Use SetStreamAsync() instead to not rely on physical file paths. Scheduled for removal in Umbraco 18.")] void Set(StringUdi udi, string physicalPath, bool copy = false); /// - /// Gets the physical path or if not found. + /// Gets the path to the file, including the file name. Returns if the file is not directly accessible. /// /// The UDI. /// - /// The physical path or if not found. + /// The path to the file, including the file name or if the file is not directly accessible. /// - /// - /// This is not pretty as *everywhere* in Deploy we take care of ignoring - /// the physical path and always rely on the virtual IFileSystem, - /// but Cloud wants to add some of these files to Git and needs the path... - /// string GetPhysicalPath(StringUdi udi); /// @@ -81,5 +106,6 @@ public interface IFileType /// /// The virtual path or if not found. /// + [Obsolete("This is not used anymore. Scheduled for removal in Umbraco 18.")] string GetVirtualPath(StringUdi udi); }