using System; using System.IO; namespace Umbraco.Core.IO.MediaPathSchemes { /// /// Implements a unique directory media path scheme. /// /// /// This scheme provides deterministic short paths, with potential collisions. /// public class UniqueMediaPathScheme : IMediaPathScheme { private const int DirectoryLength = 8; /// public string GetFilePath(IMediaFileSystem fileSystem, Guid itemGuid, Guid propertyGuid, string filename, string previous = null) { var combinedGuid = GuidUtils.Combine(itemGuid, propertyGuid); var directory = GuidUtils.ToBase32String(combinedGuid, DirectoryLength); return Path.Combine(directory, filename).Replace('\\', '/'); } /// /// /// Returning null so that does *not* /// delete any directory. This is because the above shortening of the Guid to 8 chars /// means we're increasing the risk of collision, and we don't want to delete files /// belonging to other media items. /// And, at the moment, we cannot delete directory "only if it is empty" because of /// race conditions. We'd need to implement locks in for /// this. /// public string GetDeleteDirectory(IMediaFileSystem fileSystem, string filepath) => null; } }