Skip to content

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

fix(storage): idempotent rm/mv operations with vector index sync (#284)

SeanZ5e44a0e7dd0e
diff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.py
index 6cfe7834a..00a09aaf5 100644
--- a/openviking/storage/viking_fs.py
+++ b/openviking/storage/viking_fs.py
@@ -23,6 +23,7 @@ from pathlib import PurePath
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from pyagfs import AGFSClient
+from pyagfs.exceptions import AGFSHTTPError
from openviking.server.identity import RequestContext, Role
from openviking.storage.vikingdb_interface import VikingDBInterface
@@ -253,13 +254,18 @@ class VikingFS:
async def rm(
self, uri: str, recursive: bool = False, ctx: Optional[RequestContext] = None
) -> Dict[str, Any]:
- """Delete file/directory + recursively update vector index."""
+ """Delete file/directory + recursively update vector index.
+
+ This method is idempotent: deleting a non-existent file succeeds
+ after cleaning up any orphan index records.
+ """
self._ensure_access(uri, ctx)
path = self._uri_to_path(uri, ctx=ctx)
+ target_uri = self._path_to_uri(path, ctx=ctx)
uris_to_delete = await self._collect_uris(path, recursive, ctx=ctx)
- result = self.agfs.rm(path, recursive)
- if uris_to_delete:
- await self._delete_from_vector_store(uris_to_delete, ctx=ctx)
+ uris_to_delete.append(target_uri)
+ result = self.agfs.rm(path, recursive=recursive)
+ await self._delete_from_vector_store(uris_to_delete, ctx=ctx)
return result
async def mv(
@@ -273,11 +279,19 @@ class VikingFS:
self._ensure_access(new_uri, ctx)
old_path = self._uri_to_path(old_uri, ctx=ctx)
new_path = self._uri_to_path(new_uri, ctx=ctx)
+ target_uri = self._path_to_uri(old_path, ctx=ctx)
uris_to_move = await self._collect_uris(old_path, recursive=True, ctx=ctx)
- result = self.agfs.mv(old_path, new_path)
- if uris_to_move:
+ uris_to_move.append(target_uri)
+
+ try:
+ result = self.agfs.mv(old_path, new_path)
await self._update_vector_store_uris(uris_to_move, old_uri, new_uri, ctx=ctx)
- return result
+ return result
+ except AGFSHTTPError as e:
+ if e.status_code == 404:
+ await self._delete_from_vector_store(uris_to_move, ctx=ctx)
+ logger.info(f"[VikingFS] mv source not found, cleaned orphan index: {old_uri}")
+ raise
async def grep(
self,
diff --git a/third_party/agfs/agfs-sdk/python/pyagfs/client.py b/third_party/agfs/agfs-sdk/python/pyagfs/client.py
index 53e297d49..cbc60f0c5 100644
--- a/third_party/agfs/agfs-sdk/python/pyagfs/client.py
+++ b/third_party/agfs/agfs-sdk/python/pyagfs/client.py
@@ -5,7 +5,7 @@ import time
from typing import List, Dict, Any, Optional, Union, Iterator, BinaryIO
from requests.exceptions import ConnectionError, Timeout, RequestException
-from .exceptions import AGFSClientError, AGFSNotSupportedError
+from .exceptions import AGFSClientError, AGFSHTTPError, AGFSNotSupportedError
class AGFSClient:
@@ -43,7 +43,7 @@ class AGFSClient:
raise AGFSClientError(f"Request timeout after {self.timeout}s")
elif isinstance(e, requests.exceptions.HTTPError):
# Extract useful error information from response
- if hasattr(e, 'response') and e.response is not None:
+ if hasattr(e, "response") and e.response is not None:
status_code = e.response.status_code
# Special handling for 501 Not Implemented - always raise typed error
@@ -55,35 +55,31 @@ class AGFSClient:
error_msg = "Operation not supported"
raise AGFSNotSupportedError(error_msg)
- # Try to get error message from JSON response first (priority)
+ # Try to get error message from JSON response first
+ error_msg = None
try:
error_data = e.response.json()
error_msg = error_data.get("error", "")
- if error_msg:
- # Use the server's detailed error message
- raise AGFSClientError(error_msg)
except (ValueError, KeyError, TypeError):
- # If JSON parsing fails, fall through to generic status code messages
pass
- except AGFSClientError:
- # Re-raise our own error
- raise
- # Fallback to generic messages based on status codes
- if status_code == 404:
- raise AGFSClientError("No such file or directory")
+ # Always use AGFSHTTPError to preserve status_code
+ if error_msg:
+ raise AGFSHTTPError(error_msg, status_code)
+ elif status_code == 404:
+ raise AGFSHTTPError("No such file or directory", status_code)
elif status_code == 403:
- raise AGFSClientError("Permission denied")
+ raise AGFSHTTPError("Permission denied", status_code)
elif status_code == 409:
- raise AGFSClientError("Resource already exists")
+ raise AGFSHTTPError("Resource already exists", status_code)
elif status_code == 500:
- raise AGFSClientError("Internal server error")
+ raise AGFSHTTPError("Internal server error", status_code)
elif status_code == 502:
- raise AGFSClientError("Bad Gateway - backend service unavailable")
+ raise AGFSHTTPError("Bad Gateway - backend service unavailable", status_code)
else:
- raise AGFSClientError(f"HTTP error {status_code}")
+ raise AGFSHTTPError(f"HTTP error {status_code}", status_code)
else:
- raise AGFSClientError("HTTP error")
+ raise AGFSHTTPError("HTTP error", None)
else:
# For other exceptions, re-raise with simplified message
raise AGFSClientError(str(e))
@@ -103,11 +99,11 @@ class AGFSClient:
"""
try:
response = self.session.get(f"{self.api_base}/capabilities", timeout=self.timeout)
-
+
# If capabilities endpoint doesn't exist (older server), return empty capabilities
if response.status_code == 404:
return {"version": "unknown", "features": []}
-
+
response.raise_for_status()
return response.json()
except Exception as e:
@@ -121,9 +117,7 @@ class AGFSClient:
"""List directory contents"""
try:
response = self.session.get(
- f"{self.api_base}/directories",
- params={"path": path},
- timeout=self.timeout
+ f"{self.api_base}/directories", params={"path": path}, timeout=self.timeout
)
response.raise_for_status()
data = response.json()
@@ -158,7 +152,7 @@ class AGFSClient:
f"{self.api_base}/files",
params=params,
stream=True,
- timeout=None # No timeout for streaming
+ timeout=None, # No timeout for streaming
)
response.raise_for_status()
return response
@@ -170,16 +164,16 @@ class AGFSClient:
params["size"] = str(size)
response = self.session.get(
- f"{self.api_base}/files",
- params=params,
- timeout=self.timeout
+ f"{self.api_base}/files", params=params, timeout=self.timeout
)
response.raise_for_status()
return response.content
except Exception as e:
self._handle_request_error(e)
- def write(self, path: str, data: Union[bytes, Iterator[bytes], BinaryIO], max_retries: int = 3) -> str:
+ def write(
+ self, path: str, data: Union[bytes, Iterator[bytes], BinaryIO], max_retries: int = 3
+ ) -> str:
"""Write data to file and return the response message
Args:
@@ -207,7 +201,7 @@ class AGFSClient:
f"{self.api_base}/files",
params={"path": path},
data=data, # requests supports bytes, iterator, or file-like object
- timeout=write_timeout
+ timeout=write_timeout,
)
response.raise_for_status()
result = response.json()
@@ -224,8 +218,10 @@ class AGFSClient:
if attempt < max_retries:
# Exponential backoff: 1s, 2s, 4s
- wait_time = 2 ** attempt
- print(f"⚠ Upload failed (attempt {attempt + 1}/{max_retries + 1}): {type(e).__name__}")
+ wait_time = 2**attempt
+ print(
+ f"⚠ Upload failed (attempt {attempt + 1}/{max_retries + 1}): {type(e).__name__}"
+ )
print(f" Retrying in {wait_time} seconds...")
time.sleep(wait_time)
else:
@@ -235,7 +231,7 @@ class AGFSClient:
except requests.exceptions.HTTPError as e:
# Check if it's a server error (5xx) which might be retryable
- if hasattr(e, 'response') and e.response is not None:
+ if hasattr(e, "response") and e.response is not None:
status_code = e.response.status_code
# Only retry specific server errors that indicate temporary issues
@@ -247,8 +243,10 @@ class AGFSClient:
last_error = e
if attempt < max_retries:
- wait_time = 2 ** attempt
- print(f"⚠ Server error {status_code} (attempt {attempt + 1}/{max_retries + 1})")
+ wait_time = 2**attempt
+ print(
+ f"⚠ Server error {status_code} (attempt {attempt + 1}/{max_retries + 1})"
+ )
print(f" Retrying in {wait_time} seconds...")
time.sleep(wait_time)
else:
@@ -273,9 +271,7 @@ class AGFSClient:
"""Create a new file"""
try:
response = self.session.post(
- f"{self.api_base}/files",
- params={"path": path},
- timeout=self.timeout
+ f"{self.api_base}/files", params={"path": path}, timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -288,15 +284,21 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/directories",
params={"path": path, "mode": mode},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
except Exception as e:
self._handle_request_error(e)
- def rm(self, path: str, recursive: bool = False) -> Dict[str, Any]:
- """Remove a file or directory"""
+ def rm(self, path: str, recursive: bool = False, force: bool = True) -> Dict[str, Any]:
+ """Remove a file or directory.
+
+ Args:
+ path: Path to remove.
+ recursive: Remove directories recursively.
+ force: If True (default), ignore nonexistent files (like rm -f). Idempotent by default.
+ """
try:
params = {"path": path}
if recursive:
@@ -304,10 +306,14 @@ class AGFSClient:
response = self.session.delete(
f"{self.api_base}/files",
params=params,
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
+ except requests.exceptions.HTTPError as e:
+ if force and e.response is not None and e.response.status_code == 404:
+ return {"message": "deleted"}
+ self._handle_request_error(e)
except Exception as e:
self._handle_request_error(e)
@@ -315,9 +321,7 @@ class AGFSClient:
"""Get file/directory information"""
try:
response = self.session.get(
- f"{self.api_base}/stat",
- params={"path": path},
- timeout=self.timeout
+ f"{self.api_base}/stat", params={"path": path}, timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -331,7 +335,7 @@ class AGFSClient:
f"{self.api_base}/rename",
params={"path": old_path},
json={"newPath": new_path},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -345,7 +349,7 @@ class AGFSClient:
f"{self.api_base}/chmod",
params={"path": path},
json={"mode": mode},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -356,9 +360,7 @@ class AGFSClient:
"""Touch a file (update timestamp by writing empty content)"""
try:
response = self.session.post(
- f"{self.api_base}/touch",
- params={"path": path},
- timeout=self.timeout
+ f"{self.api_base}/touch", params={"path": path}, timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -390,7 +392,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/mount",
json={"fstype": fstype, "path": path, "config": config},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -401,9 +403,7 @@ class AGFSClient:
"""Unmount a plugin"""
try:
response = self.session.post(
- f"{self.api_base}/unmount",
- json={"path": path},
- timeout=self.timeout
+ f"{self.api_base}/unmount", json={"path": path}, timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -423,7 +423,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/plugins/load",
json={"library_path": library_path},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -443,7 +443,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/plugins/unload",
json={"library_path": library_path},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -457,10 +457,7 @@ class AGFSClient:
List of plugin library paths
"""
try:
- response = self.session.get(
- f"{self.api_base}/plugins",
- timeout=self.timeout
- )
+ response = self.session.get(f"{self.api_base}/plugins", timeout=self.timeout)
response.raise_for_status()
data = response.json()
@@ -471,8 +468,11 @@ class AGFSClient:
elif "plugins" in data:
# New format - extract library paths from external plugins only
plugins = data.get("plugins", [])
- return [p.get("library_path", "") for p in plugins
- if p.get("is_external", False) and p.get("library_path")]
+ return [
+ p.get("library_path", "")
+ for p in plugins
+ if p.get("is_external", False) and p.get("library_path")
+ ]
else:
return []
except Exception as e:
@@ -490,17 +490,21 @@ class AGFSClient:
- config_params: List of configuration parameters (name, type, required, default, description)
"""
try:
- response = self.session.get(
- f"{self.api_base}/plugins",
- timeout=self.timeout
- )
+ response = self.session.get(f"{self.api_base}/plugins", timeout=self.timeout)
response.raise_for_status()
data = response.json()
return data.get("plugins", [])
except Exception as e:
self._handle_request_error(e)
- def grep(self, path: str, pattern: str, recursive: bool = False, case_insensitive: bool = False, stream: bool = False):
+ def grep(
+ self,
+ path: str,
+ pattern: str,
+ recursive: bool = False,
+ case_insensitive: bool = False,
+ stream: bool = False,
+ ):
"""Search for a pattern in files using regular expressions
Args:
@@ -534,10 +538,10 @@ class AGFSClient:
"pattern": pattern,
"recursive": recursive,
"case_insensitive": case_insensitive,
- "stream": stream
+ "stream": stream,
},
timeout=None if stream else self.timeout,
- stream=stream
+ stream=stream,
)
response.raise_for_status()
@@ -553,6 +557,7 @@ class AGFSClient:
def _parse_ndjson_stream(self, response):
"""Parse NDJSON streaming response line by line"""
import json
+
for line in response.iter_lines():
if line:
try:
@@ -584,7 +589,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/digest",
json={"algorithm": algorithm, "path": path},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -595,7 +600,9 @@ class AGFSClient:
# These APIs provide POSIX-like file handle operations for
# filesystems that support stateful file access (e.g., seek, pread/pwrite)
- def open_handle(self, path: str, flags: int = 0, mode: int = 0o644, lease: int = 60) -> 'FileHandle':
+ def open_handle(
+ self, path: str, flags: int = 0, mode: int = 0o644, lease: int = 60
+ ) -> "FileHandle":
"""Open a file handle for stateful operations
Args:
@@ -617,7 +624,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/handles/open",
params={"path": path, "flags": str(flags), "mode": str(mode), "lease": str(lease)},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
data = response.json()
@@ -632,10 +639,7 @@ class AGFSClient:
List of handle info dicts with keys: handle_id, path, flags, lease, expires_at, created_at, last_access
"""
try:
- response = self.session.get(
- f"{self.api_base}/handles",
- timeout=self.timeout
- )
+ response = self.session.get(f"{self.api_base}/handles", timeout=self.timeout)
response.raise_for_status()
data = response.json()
return data.get("handles", [])
@@ -653,8 +657,7 @@ class AGFSClient:
"""
try:
response = self.session.get(
- f"{self.api_base}/handles/{handle_id}",
- timeout=self.timeout
+ f"{self.api_base}/handles/{handle_id}", timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -672,8 +675,7 @@ class AGFSClient:
"""
try:
response = self.session.delete(
- f"{self.api_base}/handles/{handle_id}",
- timeout=self.timeout
+ f"{self.api_base}/handles/{handle_id}", timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -696,9 +698,7 @@ class AGFSClient:
if offset is not None:
params["offset"] = str(offset)
response = self.session.get(
- f"{self.api_base}/handles/{handle_id}/read",
- params=params,
- timeout=self.timeout
+ f"{self.api_base}/handles/{handle_id}/read", params=params, timeout=self.timeout
)
response.raise_for_status()
return response.content
@@ -724,7 +724,7 @@ class AGFSClient:
f"{self.api_base}/handles/{handle_id}/write",
params=params,
data=data,
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
result = response.json()
@@ -747,7 +747,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/handles/{handle_id}/seek",
params={"offset": str(offset), "whence": str(whence)},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
result = response.json()
@@ -766,8 +766,7 @@ class AGFSClient:
"""
try:
response = self.session.post(
- f"{self.api_base}/handles/{handle_id}/sync",
- timeout=self.timeout
+ f"{self.api_base}/handles/{handle_id}/sync", timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -785,8 +784,7 @@ class AGFSClient:
"""
try:
response = self.session.get(
- f"{self.api_base}/handles/{handle_id}/stat",
- timeout=self.timeout
+ f"{self.api_base}/handles/{handle_id}/stat", timeout=self.timeout
)
response.raise_for_status()
return response.json()
@@ -807,7 +805,7 @@ class AGFSClient:
response = self.session.post(
f"{self.api_base}/handles/{handle_id}/renew",
params={"lease": str(lease)},
- timeout=self.timeout
+ timeout=self.timeout,
)
response.raise_for_status()
return response.json()
@@ -989,7 +987,7 @@ class FileHandle:
self._client.close_handle(self._handle_id)
self._closed = True
- def __enter__(self) -> 'FileHandle':
+ def __enter__(self) -> "FileHandle":
return self
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
diff --git a/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go b/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
index c0df1b094..c34b44f60 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/localfs/localfs.go
@@ -134,7 +134,7 @@ func (fs *LocalFS) Remove(path string) error {
info, err := os.Stat(localPath)
if err != nil {
if os.IsNotExist(err) {
- return fmt.Errorf("no such file or directory: %s", path)
+ return filesystem.NewNotFoundError("remove", path)
}
return fmt.Errorf("failed to stat: %w", err)
}
@@ -167,7 +167,7 @@ func (fs *LocalFS) RemoveAll(path string) error {
// Check if exists
if _, err := os.Stat(localPath); os.IsNotExist(err) {
- return fmt.Errorf("no such file or directory: %s", path)
+ return filesystem.NewNotFoundError("remove", path)
}
// Remove recursively
@@ -189,7 +189,7 @@ func (fs *LocalFS) Read(path string, offset int64, size int64) ([]byte, error) {
info, err := os.Stat(localPath)
if err != nil {
if os.IsNotExist(err) {
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("read", path)
}
return nil, fmt.Errorf("failed to stat: %w", err)
}
@@ -364,7 +364,7 @@ func (fs *LocalFS) Stat(path string) (*filesystem.FileInfo, error) {
info, err := os.Stat(localPath)
if err != nil {
if os.IsNotExist(err) {
- return nil, fmt.Errorf("no such file or directory: %s", path)
+ return nil, filesystem.NewNotFoundError("stat", path)
}
return nil, fmt.Errorf("failed to stat: %w", err)
}
@@ -394,7 +394,7 @@ func (fs *LocalFS) Rename(oldPath, newPath string) error {
// Check if old path exists
if _, err := os.Stat(oldLocalPath); os.IsNotExist(err) {
- return fmt.Errorf("no such file or directory: %s", oldPath)
+ return filesystem.NewNotFoundError("rename", oldPath)
}
// Check if new path parent directory exists
@@ -420,7 +420,7 @@ func (fs *LocalFS) Chmod(path string, mode uint32) error {
// Check if exists
if _, err := os.Stat(localPath); os.IsNotExist(err) {
- return fmt.Errorf("no such file or directory: %s", path)
+ return filesystem.NewNotFoundError("chmod", path)
}
// Change permissions
@@ -442,7 +442,7 @@ func (fs *LocalFS) Open(path string) (io.ReadCloser, error) {
f, err := os.Open(localPath)
if err != nil {
if os.IsNotExist(err) {
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("open", path)
}
return nil, fmt.Errorf("failed to open file: %w", err)
}
@@ -554,7 +554,7 @@ func (fs *LocalFS) OpenStream(path string) (filesystem.StreamReader, error) {
info, err := os.Stat(localPath)
if err != nil {
if os.IsNotExist(err) {
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("grep", path)
}
return nil, fmt.Errorf("failed to stat: %w", err)
}
diff --git a/third_party/agfs/agfs-server/pkg/plugins/memfs/memoryfs.go b/third_party/agfs/agfs-server/pkg/plugins/memfs/memoryfs.go
index 1042801fb..79328422a 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/memfs/memoryfs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/memfs/memoryfs.go
@@ -79,7 +79,7 @@ func (mfs *MemoryFS) getNode(path string) (*Node, error) {
}
next, exists := current.Children[part]
if !exists {
- return nil, fmt.Errorf("no such file or directory: %s", path)
+ return nil, filesystem.NewNotFoundError("getNode", path)
}
current = next
}
@@ -177,7 +177,7 @@ func (mfs *MemoryFS) Remove(path string) error {
node, exists := parent.Children[name]
if !exists {
- return fmt.Errorf("no such file or directory: %s", path)
+ return filesystem.NewNotFoundError("remove", path)
}
if node.IsDir && len(node.Children) > 0 {
@@ -205,7 +205,7 @@ func (mfs *MemoryFS) RemoveAll(path string) error {
}
if _, exists := parent.Children[name]; !exists {
- return fmt.Errorf("no such file or directory: %s", path)
+ return filesystem.NewNotFoundError("remove", path)
}
delete(parent.Children, name)
@@ -377,7 +377,7 @@ func (mfs *MemoryFS) Rename(oldPath, newPath string) error {
node, exists := oldParent.Children[oldName]
if !exists {
- return fmt.Errorf("no such file or directory: %s", oldPath)
+ return filesystem.NewNotFoundError("rename", oldPath)
}
newParent, newName, err := mfs.getParentNode(newPath)
diff --git a/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go b/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
index 8b247a854..d8d481b0d 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/queuefs/queuefs.go
@@ -517,7 +517,7 @@ func (qfs *queueFS) Read(path string, offset int64, size int64) ([]byte, error)
}
if operation == "" {
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("read", path)
}
var data []byte
@@ -533,7 +533,7 @@ func (qfs *queueFS) Read(path string, offset int64, size int64) ([]byte, error)
// Write-only files
return []byte(""), fmt.Errorf("permission denied: %s is write-only", path)
default:
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("read", path)
}
if err != nil {
@@ -823,7 +823,7 @@ func (qfs *queueFS) Stat(p string) (*filesystem.FileInfo, error) {
}
if !hasChildren {
qfs.plugin.mu.RUnlock()
- return nil, fmt.Errorf("no such file or directory: %s", p)
+ return nil, filesystem.NewNotFoundError("stat", p)
}
}
qfs.plugin.mu.RUnlock()
@@ -840,7 +840,7 @@ func (qfs *queueFS) Stat(p string) (*filesystem.FileInfo, error) {
// Control file stat
if operation == "" {
- return nil, fmt.Errorf("no such file: %s", p)
+ return nil, filesystem.NewNotFoundError("stat", p)
}
mode := uint32(0644)
diff --git a/third_party/agfs/agfs-server/pkg/plugins/serverinfofs/serverinfofs.go b/third_party/agfs/agfs-server/pkg/plugins/serverinfofs/serverinfofs.go
index 9b1257443..23932564b 100644
--- a/third_party/agfs/agfs-server/pkg/plugins/serverinfofs/serverinfofs.go
+++ b/third_party/agfs/agfs-server/pkg/plugins/serverinfofs/serverinfofs.go
@@ -182,7 +182,7 @@ func (fs *serverInfoFS) getServerInfo() map[string]interface{} {
func (fs *serverInfoFS) Read(path string, offset int64, size int64) ([]byte, error) {
if !fs.isValidPath(path) {
- return nil, fmt.Errorf("no such file or directory: %s", path)
+ return nil, filesystem.NewNotFoundError("read", path)
}
if path == "/" {
@@ -239,7 +239,7 @@ func (fs *serverInfoFS) Read(path string, offset int64, size int64) ([]byte, err
data = []byte(fs.plugin.GetReadme())
default:
- return nil, fmt.Errorf("no such file: %s", path)
+ return nil, filesystem.NewNotFoundError("read", path)
}
// if data is not ended by '\n' then add it
@@ -339,7 +339,7 @@ func (fs *serverInfoFS) ReadDir(path string) ([]filesystem.FileInfo, error) {
func (fs *serverInfoFS) Stat(path string) (*filesystem.FileInfo, error) {
if !fs.isValidPath(path) {
- return nil, fmt.Errorf("no such file or directory: %s", path)
+ return nil, filesystem.NewNotFoundError("stat", path)
}
now := time.Now()