@@ -222,7 +222,7 @@ func (c *HTTPClient) CreateRevisionFromPaths(ctx context.Context, paths []string
222
222
for _ , pth := range paths {
223
223
info , err := os .Stat (pth )
224
224
if err != nil {
225
- return uuid .Nil , fmt . Errorf ( "failed to stat path %s: %w" , pth , err )
225
+ return uuid .Nil , uploadrevision . NewFileAccessError ( pth , err )
226
226
}
227
227
228
228
if info .IsDir () {
@@ -244,13 +244,31 @@ func (c *HTTPClient) CreateRevisionFromPaths(ctx context.Context, paths []string
244
244
}
245
245
246
246
// CreateRevisionFromDir uploads a directory and all its contents, returning a revision ID.
247
- // This is a convenience method equivalent to CreateRevisionFromPaths with a single directory.
247
+ // This is a convenience method for validating the directory path and calling CreateRevisionFromPaths with a single directory path .
248
248
func (c * HTTPClient ) CreateRevisionFromDir (ctx context.Context , dirPath string , opts UploadOptions ) (RevisionID , error ) {
249
+ info , err := os .Stat (dirPath )
250
+ if err != nil {
251
+ return uuid .Nil , uploadrevision .NewFileAccessError (dirPath , err )
252
+ }
253
+
254
+ if ! info .IsDir () {
255
+ return uuid .Nil , fmt .Errorf ("the provided path is not a directory: %s" , dirPath )
256
+ }
257
+
249
258
return c .CreateRevisionFromPaths (ctx , []string {dirPath }, opts )
250
259
}
251
260
252
261
// CreateRevisionFromFile uploads a single file, returning a revision ID.
253
- // This is a convenience method equivalent to CreateRevisionFromPaths with a single file.
262
+ // This is a convenience method for validating the file path and calling CreateRevisionFromPaths with a single file path .
254
263
func (c * HTTPClient ) CreateRevisionFromFile (ctx context.Context , filePath string , opts UploadOptions ) (RevisionID , error ) {
264
+ info , err := os .Stat (filePath )
265
+ if err != nil {
266
+ return uuid .Nil , uploadrevision .NewFileAccessError (filePath , err )
267
+ }
268
+
269
+ if ! info .Mode ().IsRegular () {
270
+ return uuid .Nil , fmt .Errorf ("the provided path is not a regular file: %s" , filePath )
271
+ }
272
+
255
273
return c .CreateRevisionFromPaths (ctx , []string {filePath }, opts )
256
274
}
0 commit comments