1414
1515namespace SharpGrip . FileSystem . Adapters . AmazonS3
1616{
17- public class AmazonS3Adapter : Adapter
17+ public class AmazonS3Adapter : Adapter < AmazonS3AdapterConfiguration , string , string >
1818 {
1919 private readonly IAmazonS3 client ;
2020 private readonly string bucketName ;
2121
22- public AmazonS3Adapter ( string prefix , string rootPath , IAmazonS3 client , string bucketName ) : base ( prefix , rootPath )
22+ public AmazonS3Adapter ( string prefix , string rootPath , IAmazonS3 client , string bucketName , Action < AmazonS3AdapterConfiguration > ? configuration = null ) : base ( prefix , rootPath , configuration )
2323 {
2424 this . client = client ;
2525 this . bucketName = bucketName ;
@@ -61,12 +61,7 @@ public override async Task<IFile> GetFileAsync(string virtualPath, CancellationT
6161
6262 public override async Task < IDirectory > GetDirectoryAsync ( string virtualPath , CancellationToken cancellationToken = default )
6363 {
64- var path = GetPath ( virtualPath ) ;
65-
66- if ( ! path . EndsWith ( "/" ) )
67- {
68- path += "/" ;
69- }
64+ var path = GetPath ( virtualPath ) . RemoveLeadingForwardSlash ( ) . EnsureTrailingForwardSlash ( ) ;
7065
7166 try
7267 {
@@ -109,12 +104,7 @@ public override async Task<IDirectory> GetDirectoryAsync(string virtualPath, Can
109104 public override async Task < IEnumerable < IFile > > GetFilesAsync ( string virtualPath = "" , CancellationToken cancellationToken = default )
110105 {
111106 await GetDirectoryAsync ( virtualPath , cancellationToken ) ;
112- var path = GetPath ( virtualPath ) ;
113-
114- if ( ! path . EndsWith ( "/" ) )
115- {
116- path += "/" ;
117- }
107+ var path = GetPath ( virtualPath ) . EnsureTrailingForwardSlash ( ) ;
118108
119109 if ( path == "/" )
120110 {
@@ -134,7 +124,6 @@ public override async Task<IEnumerable<IFile>> GetFilesAsync(string virtualPath
134124
135125 foreach ( var item in response . S3Objects )
136126 {
137- // var itemName = item.Key.Substring(0, item.Key.Length - path.Length);
138127 var itemName = item . Key . Substring ( path . Length ) . RemoveLeadingForwardSlash ( ) ;
139128
140129 if ( ! item . Key . EndsWith ( "/" ) && ! itemName . Contains ( '/' ) )
@@ -157,12 +146,7 @@ public override async Task<IEnumerable<IFile>> GetFilesAsync(string virtualPath
157146 public override async Task < IEnumerable < IDirectory > > GetDirectoriesAsync ( string virtualPath = "" , CancellationToken cancellationToken = default )
158147 {
159148 await GetDirectoryAsync ( virtualPath , cancellationToken ) ;
160- var path = GetPath ( virtualPath ) ;
161-
162- if ( ! path . EndsWith ( "/" ) )
163- {
164- path += "/" ;
165- }
149+ var path = GetPath ( virtualPath ) . EnsureTrailingForwardSlash ( ) ;
166150
167151 if ( path == "/" )
168152 {
@@ -208,8 +192,7 @@ public override async Task CreateDirectoryAsync(string virtualPath, Cancellation
208192 throw new DirectoryExistsException ( GetPath ( virtualPath ) , Prefix ) ;
209193 }
210194
211- var path = GetPath ( virtualPath ) ;
212- path = path . EndsWith ( "/" ) ? path : path + "/" ;
195+ var path = GetPath ( virtualPath ) . EnsureTrailingForwardSlash ( ) ;
213196
214197 try
215198 {
@@ -226,8 +209,7 @@ public override async Task DeleteDirectoryAsync(string virtualPath, Cancellation
226209 {
227210 await GetDirectoryAsync ( virtualPath , cancellationToken ) ;
228211
229- var path = GetPath ( virtualPath ) ;
230- path = path . EndsWith ( "/" ) ? path : path + "/" ;
212+ var path = GetPath ( virtualPath ) . EnsureTrailingForwardSlash ( ) ;
231213
232214 try
233215 {
0 commit comments