|
|
@ -82,6 +82,9 @@ func (fs Filesystem) listObjects(bucket, prefix, marker, delimiter string, maxKe |
|
|
|
if path == walkPath { |
|
|
|
if path == walkPath { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if info.IsDir() && delimiter == "" { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
// For all incoming directories add a ending separator.
|
|
|
|
// For all incoming directories add a ending separator.
|
|
|
|
if info.IsDir() { |
|
|
|
if info.IsDir() { |
|
|
|
path = path + string(os.PathSeparator) |
|
|
|
path = path + string(os.PathSeparator) |
|
|
@ -89,10 +92,6 @@ func (fs Filesystem) listObjects(bucket, prefix, marker, delimiter string, maxKe |
|
|
|
// Extract object name.
|
|
|
|
// Extract object name.
|
|
|
|
objectName := strings.TrimPrefix(path, bucketPathPrefix) |
|
|
|
objectName := strings.TrimPrefix(path, bucketPathPrefix) |
|
|
|
if strings.HasPrefix(objectName, prefix) { |
|
|
|
if strings.HasPrefix(objectName, prefix) { |
|
|
|
// For objectName lesser than marker, ignore.
|
|
|
|
|
|
|
|
if marker >= objectName { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
object := ObjectMetadata{ |
|
|
|
object := ObjectMetadata{ |
|
|
|
Object: objectName, |
|
|
|
Object: objectName, |
|
|
|
Created: info.ModTime(), |
|
|
|
Created: info.ModTime(), |
|
|
@ -119,9 +118,9 @@ func (fs Filesystem) listObjects(bucket, prefix, marker, delimiter string, maxKe |
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
select { |
|
|
|
// Timeout after 10 seconds if request did not arrive for
|
|
|
|
// Timeout after 1 seconds if request did not arrive for
|
|
|
|
// the given list parameters.
|
|
|
|
// the given list parameters.
|
|
|
|
case <-time.After(10 * time.Second): |
|
|
|
case <-time.After(1 * time.Second): |
|
|
|
quitWalker <- true // Quit file path walk if running.
|
|
|
|
quitWalker <- true // Quit file path walk if running.
|
|
|
|
// Send back the hash for this request.
|
|
|
|
// Send back the hash for this request.
|
|
|
|
fs.timeoutReqCh <- fnvSum(bucket, prefix, marker, delimiter) |
|
|
|
fs.timeoutReqCh <- fnvSum(bucket, prefix, marker, delimiter) |
|
|
@ -135,24 +134,52 @@ func (fs Filesystem) listObjects(bucket, prefix, marker, delimiter string, maxKe |
|
|
|
resp := ListObjectsResult{} |
|
|
|
resp := ListObjectsResult{} |
|
|
|
var count int |
|
|
|
var count int |
|
|
|
for object := range walkerCh { |
|
|
|
for object := range walkerCh { |
|
|
|
if count == maxKeys { |
|
|
|
// Verify if the object is lexically smaller than
|
|
|
|
resp.IsTruncated = true |
|
|
|
// the marker, we will skip those objects.
|
|
|
|
break |
|
|
|
if marker >= object.Object { |
|
|
|
} |
|
|
|
|
|
|
|
// If object is a directory.
|
|
|
|
|
|
|
|
if object.Mode.IsDir() { |
|
|
|
|
|
|
|
if delimiter == "" { |
|
|
|
|
|
|
|
// Skip directories for recursive listing.
|
|
|
|
|
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if delimiter != "" { |
|
|
|
|
|
|
|
// Prefixes are only valid wth delimiters, and
|
|
|
|
|
|
|
|
// for filesystem backend they are only valid
|
|
|
|
|
|
|
|
// if they are directories.
|
|
|
|
|
|
|
|
if object.Mode.IsDir() { |
|
|
|
resp.Prefixes = append(resp.Prefixes, object.Object) |
|
|
|
resp.Prefixes = append(resp.Prefixes, object.Object) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
// Rest of them are treated as files.
|
|
|
|
resp.Objects = append(resp.Objects, object) |
|
|
|
resp.Objects = append(resp.Objects, object) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// In-case of no delimiters, there are no
|
|
|
|
|
|
|
|
// prefixes all are considered to be objects.
|
|
|
|
|
|
|
|
resp.Objects = append(resp.Objects, object) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
count++ // Bump the counter
|
|
|
|
|
|
|
|
// Verify if we have reached the maxKeys requested.
|
|
|
|
|
|
|
|
if count == maxKeys { |
|
|
|
|
|
|
|
if delimiter != "" { |
|
|
|
// Set the next marker for the next request.
|
|
|
|
// Set the next marker for the next request.
|
|
|
|
resp.NextMarker = object.Object |
|
|
|
// This element is set only if you have delimiter set.
|
|
|
|
count++ |
|
|
|
// If response does not include the NextMaker and it is
|
|
|
|
|
|
|
|
// truncated, you can use the value of the last Key in the
|
|
|
|
|
|
|
|
// response as the marker in the subsequent request to get the
|
|
|
|
|
|
|
|
// next set of object keys.
|
|
|
|
|
|
|
|
if len(resp.Objects) > 0 { |
|
|
|
|
|
|
|
// NextMarker is only set when there
|
|
|
|
|
|
|
|
// are more than maxKeys worth of
|
|
|
|
|
|
|
|
// objects for a given prefix path.
|
|
|
|
|
|
|
|
resp.NextMarker = resp.Objects[len(resp.Objects)-1:][0].Object |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Set truncated boolean to indicate the
|
|
|
|
|
|
|
|
// client to send the next batch of requests.
|
|
|
|
|
|
|
|
resp.IsTruncated = true |
|
|
|
|
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Set the marker right here for the new set of the
|
|
|
|
|
|
|
|
// values coming in the from the client.
|
|
|
|
|
|
|
|
marker = resp.NextMarker |
|
|
|
req.respCh <- resp |
|
|
|
req.respCh <- resp |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -283,13 +310,5 @@ func (fs Filesystem) ListObjects(bucket, prefix, marker, delimiter string, maxKe |
|
|
|
for i := range resp.Objects { |
|
|
|
for i := range resp.Objects { |
|
|
|
resp.Objects[i].Object = filepath.ToSlash(resp.Objects[i].Object) |
|
|
|
resp.Objects[i].Object = filepath.ToSlash(resp.Objects[i].Object) |
|
|
|
} |
|
|
|
} |
|
|
|
if reqParams.Delimiter == "" { |
|
|
|
|
|
|
|
// This element is set only if you have delimiter set.
|
|
|
|
|
|
|
|
// If response does not include the NextMaker and it is
|
|
|
|
|
|
|
|
// truncated, you can use the value of the last Key in the
|
|
|
|
|
|
|
|
// response as the marker in the subsequent request to get the
|
|
|
|
|
|
|
|
// next set of object keys.
|
|
|
|
|
|
|
|
resp.NextMarker = "" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return resp, nil |
|
|
|
return resp, nil |
|
|
|
} |
|
|
|
} |
|
|
|