From 231faa8b96db8a6d4f965e3435608e5da1eeba93 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Thu, 31 Oct 2024 15:32:07 -0400 Subject: [PATCH] fix: remove workspace get dir We can no longer assume that a workspace is a directory. Therefore, it doesn't make sense to provide a method for getting the directory of a workspace. Signed-off-by: Donnie Adams --- pkg/api/handlers/files.go | 7 ++----- pkg/workspace/workspace.go | 13 ------------- 2 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 pkg/workspace/workspace.go diff --git a/pkg/api/handlers/files.go b/pkg/api/handlers/files.go index 9e702ba97..1bf414302 100644 --- a/pkg/api/handlers/files.go +++ b/pkg/api/handlers/files.go @@ -13,7 +13,6 @@ import ( "github.com/otto8-ai/otto8/pkg/api" v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.gptscript.ai/v1" "github.com/otto8-ai/otto8/pkg/storage/selectors" - "github.com/otto8-ai/otto8/pkg/workspace" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -98,7 +97,7 @@ func uploadKnowledgeToWorkspace(req api.Context, gClient *gptscript.GPTScript, w file := v1.KnowledgeFile{ ObjectMeta: metav1.ObjectMeta{ Name: v1.ObjectNameFromAbsolutePath( - filepath.Join(workspace.GetDir(ws.Status.WorkspaceID), filename), + filepath.Join(ws.Status.WorkspaceID, filename), ), Namespace: ws.Namespace, }, @@ -212,12 +211,10 @@ func deleteKnowledge(req api.Context, filename string, knowledgeSetName string) } func deleteKnowledgeFromWorkspace(req api.Context, filename string, ws *v1.Workspace) error { - fileObjectName := v1.ObjectNameFromAbsolutePath(filepath.Join(workspace.GetDir(ws.Status.WorkspaceID), filename)) - if err := req.Delete(&v1.KnowledgeFile{ ObjectMeta: metav1.ObjectMeta{ Namespace: ws.Namespace, - Name: fileObjectName, + Name: v1.ObjectNameFromAbsolutePath(filepath.Join(ws.Status.WorkspaceID, filename)), }, }); err != nil { return err diff --git a/pkg/workspace/workspace.go b/pkg/workspace/workspace.go deleted file mode 100644 index 2b1f394ee..000000000 --- a/pkg/workspace/workspace.go +++ /dev/null @@ -1,13 +0,0 @@ -package workspace - -import ( - "strings" -) - -func GetDir(workspaceID string) string { - provider, path, _ := strings.Cut(workspaceID, "://") - if provider == "directory" { - return path - } - panic("workspaceID must start with directory://") -}