🟡 medium - bug
File: pkg/tools/builtin/filesystem.go (line 624)
Code
for _, path := range args.Paths {
resolvedPath := t.resolvePath(path)
if err := syscall.Rmdir(resolvedPath); err != nil {
if errors.Is(err, syscall.ENOTDIR) {
return tools.ResultError(fmt.Sprintf("Error: %s is not a directory", path)), nil
}
return tools.ResultError(fmt.Sprintf("Error removing directory %s: %s", path, err)), nil
}
results = append(results, fmt.Sprintf("Directory removed successfully: %s", path))
}
Problem
The syscall.Rmdir function is a Unix-specific system call. While os.Remove on Go can handle directory removal (if empty) in a cross-platform way, using syscall.Rmdir directly makes this function non-portable to Windows. On Windows, syscall.Rmdir would likely fail with an ENOSYS error or similar, meaning the "remove_directory" tool would not work as expected on Windows systems.
Suggested Fix
Replace syscall.Rmdir with os.Remove(resolvedPath). The os.Remove function is cross-platform and handles both files and empty directories. It returns an error if the directory is not empty, which is consistent with the intent of "remove empty directories".
if err := os.Remove(resolvedPath); err != nil {
if errors.Is(err, os.ErrNotExist) { // Handle "not found" explicitly if desired
return tools.ResultError(fmt.Sprintf("Error: directory %s not found", path)), nil
}
if errors.Is(err, os.ErrInvalid) || strings.Contains(err.Error(), "directory not empty") { // Check for non-empty or not a directory
return tools.ResultError(fmt.Sprintf("Error removing directory %s: %s (directory might not be empty or is not a directory)", path, err)), nil
}
return tools.ResultError(fmt.Sprintf("Error removing directory %s: %s", path, err)), nil
}
Found by nightly codebase scan
🟡 medium - bug
File:
pkg/tools/builtin/filesystem.go(line 624)Code
Problem
The
syscall.Rmdirfunction is a Unix-specific system call. Whileos.Removeon Go can handle directory removal (if empty) in a cross-platform way, usingsyscall.Rmdirdirectly makes this function non-portable to Windows. On Windows,syscall.Rmdirwould likely fail with anENOSYSerror or similar, meaning the "remove_directory" tool would not work as expected on Windows systems.Suggested Fix
Replace
syscall.Rmdirwithos.Remove(resolvedPath). Theos.Removefunction is cross-platform and handles both files and empty directories. It returns an error if the directory is not empty, which is consistent with the intent of "remove empty directories".Found by nightly codebase scan