Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix: When the AGFS backend is s3, the error "pyagfs.exceptions.AGFSClientError: parent directory does not exist" occurs. (#254)

baojun-zhang66fdea27af6b
diff --git a/third_party/agfs/agfs-server/pkg/plugins/s3fs/client.go b/third_party/agfs/agfs-server/pkg/plugins/s3fs/client.go
index ca649542a..6b4c141fe 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/s3fs/client.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/s3fs/client.go
@@ -393,12 +393,24 @@ func (c *S3Client) ObjectExists(ctx context.Context, path string) (bool, error)
// DirectoryExists checks if a directory exists (has objects with the prefix)
// Optimized to use a single ListObjectsV2 call
func (c *S3Client) DirectoryExists(ctx context.Context, path string) (bool, error) {
- prefix := c.buildKey(path)
- if prefix != "" && !strings.HasSuffix(prefix, "/") {
- prefix += "/"
+ // First check if directory marker exists
+ dirKey := c.buildKey(path)
+ if !strings.HasSuffix(dirKey, "/") {
+ dirKey += "/"
}
-
- // Single ListObjectsV2 call to check both directory marker and children
+
+ // Try HeadObject to check if directory marker exists
+ _, err := c.client.HeadObject(ctx, &s3.HeadObjectInput{
+ Bucket: aws.String(c.bucket),
+ Key: aws.String(dirKey),
+ })
+ if err == nil {
+ // Directory marker exists
+ return true, nil
+ }
+
+ // If directory marker doesn't exist, check if there are any objects with this prefix
+ prefix := dirKey
result, err := c.client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
Bucket: aws.String(c.bucket),
Prefix: aws.String(prefix),