@@ -88,6 +88,7 @@ type CacheObjectLayer interface {
88
88
DeleteObjects (ctx context.Context , bucket string , objects []ObjectToDelete , opts ObjectOptions ) ([]DeletedObject , []error )
89
89
PutObject (ctx context.Context , bucket , object string , data * PutObjReader , opts ObjectOptions ) (objInfo ObjectInfo , err error )
90
90
CopyObject (ctx context.Context , srcBucket , srcObject , destBucket , destObject string , srcInfo ObjectInfo , srcOpts , dstOpts ObjectOptions ) (objInfo ObjectInfo , err error )
91
+ ListObjects (ctx context.Context , bucket , prefix , marker , delimiter string , maxKeys int ) (result ListObjectsInfo , err error )
91
92
ListObjectsV2 (ctx context.Context , bucket , prefix , continuationToken , delimiter string , maxKeys int , fetchOwner bool , startAfter string ) (result ListObjectsV2Info , err error )
92
93
// Multipart operations.
93
94
NewMultipartUpload (ctx context.Context , bucket , object string , opts ObjectOptions ) (uploadID string , err error )
@@ -493,6 +494,57 @@ func (c *cacheObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dst
493
494
return copyObjectFn (ctx , srcBucket , srcObject , dstBucket , dstObject , srcInfo , srcOpts , dstOpts )
494
495
}
495
496
497
+ // ListObjects from disk cache
498
+ func (c * cacheObjects ) ListObjects (ctx context.Context , bucket , prefix , marker , delimiter string , maxKeys int ) (result ListObjectsInfo , err error ) {
499
+ objInfos := []ObjectInfo {}
500
+ prefixes := []string {}
501
+ for _ , cache := range c .cache {
502
+ dir := cache .dir
503
+ fmt .Println ("cache dirss" , dir )
504
+ filterFn := func (name string , typ os.FileMode ) error {
505
+ if name == minioMetaBucket {
506
+ // Proceed to next file.
507
+ return nil
508
+ }
509
+ cacheDir := pathJoin (cache .dir , name )
510
+ fmt .Println ("Harsh cachedirr" , cacheDir )
511
+ meta , _ , _ , err := cache .statCachedMeta (ctx , cacheDir )
512
+ if err != nil {
513
+ return nil
514
+ }
515
+ objInfo := meta .ToObjectInfo ()
516
+ if objInfo .Bucket == bucket {
517
+ if strings .HasPrefix (objInfo .Name , prefix ) {
518
+ trimmed := strings .TrimPrefix (objInfo .Name , prefix )
519
+ parts := strings .Split (trimmed , delimiter )
520
+ if len (parts ) > 0 && parts [0 ] != "" {
521
+ if (len (objInfos ) + len (prefixes )) < maxKeys {
522
+ if len (parts ) == 1 {
523
+ // If there's only one part, it's a file
524
+ objInfos = append (objInfos , objInfo )
525
+ } else {
526
+ // If there are more parts, it's a folder
527
+ prefixes = append (prefixes , prefix + parts [0 ]+ delimiter )
528
+ }
529
+ }
530
+ }
531
+ }
532
+ }
533
+ return nil
534
+ }
535
+
536
+ if err := readDirFn (cache .dir , filterFn ); err != nil {
537
+ logger .LogIf (ctx , err )
538
+ return ListObjectsInfo {}, err
539
+ }
540
+ }
541
+ fmt .Println ("Harsh ListObjectsInfo len from cache" , len (objInfos ))
542
+ return ListObjectsInfo {
543
+ Objects : objInfos ,
544
+ Prefixes : unique (prefixes ),
545
+ }, nil
546
+ }
547
+
496
548
// ListObjectsV2 from disk cache
497
549
func (c * cacheObjects ) ListObjectsV2 (ctx context.Context , bucket , prefix , continuationToken , delimiter string , maxKeys int , fetchOwner bool , startAfter string ) (result ListObjectsV2Info , err error ) {
498
550
objInfos := []ObjectInfo {}
@@ -588,10 +640,10 @@ func (c *cacheObjects) skipCache() bool {
588
640
589
641
// Returns true if object should be excluded from cache
590
642
func (c * cacheObjects ) isCacheExclude (bucket , object string ) bool {
591
- // exclude directories from cache
592
- if strings .HasSuffix (object , SlashSeparator ) {
593
- return true
594
- }
643
+ // uncomment this to exclude directories from cache
644
+ // if strings.HasSuffix(object, SlashSeparator) {
645
+ // return true
646
+ // }
595
647
for _ , pattern := range c .exclude {
596
648
matchStr := fmt .Sprintf ("%s/%s" , bucket , object )
597
649
if ok := wildcard .MatchSimple (pattern , matchStr ); ok {
@@ -718,6 +770,7 @@ func (c *cacheObjects) migrateCacheFromV1toV2(ctx context.Context) {
718
770
719
771
// PutObject - caches the uploaded object for single Put operations
720
772
func (c * cacheObjects ) PutObject (ctx context.Context , bucket , object string , r * PutObjReader , opts ObjectOptions ) (objInfo ObjectInfo , err error ) {
773
+ fmt .Println ("Object to be cached" , object )
721
774
putObjectFn := c .InnerPutObjectFn
722
775
dcache , err := c .getCacheToLoc (ctx , bucket , object )
723
776
if err != nil {
0 commit comments