Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asabya committed Dec 14, 2023
1 parent 544286d commit 2b53f73
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion pkg/api/pod_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api

import (
"encoding/json"
"errors"
"net/http"

"github.com/fairdatasociety/fairOS-dfs/pkg/auth"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (h *Handler) PodDeleteHandler(w http.ResponseWriter, r *http.Request) {
// delete pod
err = h.dfsAPI.DeletePod(podName, sessionId)
if err != nil {
if err == dfs.ErrUserNotLoggedIn {
if errors.Is(err, dfs.ErrUserNotLoggedIn) {
h.logger.Errorf("delete pod: %v", err)
jsonhttp.BadRequest(w, &response{Message: "delete pod: " + err.Error()})
return
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/pod_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api

import (
"encoding/json"
"errors"
"net/http"

"github.com/fairdatasociety/fairOS-dfs/pkg/auth"
Expand Down Expand Up @@ -80,8 +81,8 @@ func (h *Handler) PodOpenHandler(w http.ResponseWriter, r *http.Request) {
// open pod
_, err = h.dfsAPI.OpenPod(pod, sessionId)
if err != nil {
if err == dfs.ErrUserNotLoggedIn ||
err == p.ErrInvalidPodName {
if errors.Is(err, dfs.ErrUserNotLoggedIn) ||
errors.Is(err, p.ErrInvalidPodName) {
h.logger.Errorf("pod open: %v", err)
jsonhttp.NotFound(w, &response{Message: "pod open: " + err.Error()})
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/blockstore/bee/mock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func NewTestBeeServer(t *testing.T, o TestServerOptions) string {
if o.BeeMode == api.UnknownMode {
o.BeeMode = api.FullMode
}

o.CORSAllowedOrigins = append(o.CORSAllowedOrigins, "*")
s := api.New(o.PublicKey, o.PSSPublicKey, o.EthereumAddress, o.Logger, transaction, o.BatchStore, o.BeeMode, true, true, backend, o.CORSAllowedOrigins, inmemstore.New())
testutil.CleanupCloser(t, s)

Expand Down
11 changes: 3 additions & 8 deletions pkg/dfs/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"path/filepath"
"strconv"
"strings"

c "github.com/fairdatasociety/fairOS-dfs/pkg/collection"

"github.com/fairdatasociety/fairOS-dfs/pkg/account"
c "github.com/fairdatasociety/fairOS-dfs/pkg/collection"
"github.com/fairdatasociety/fairOS-dfs/pkg/contracts/datahub"
"github.com/fairdatasociety/fairOS-dfs/pkg/dir"
"github.com/fairdatasociety/fairOS-dfs/pkg/feed"
Expand Down Expand Up @@ -65,15 +65,13 @@ func (a *API) DeletePod(podName, sessionId string) error {
if ui == nil {
return ErrUserNotLoggedIn
}

// delete all the directory, files, and database tables under this pod from
// the Swarm network.
podInfo, _, err := ui.GetPod().GetPodInfo(podName)
if err != nil {
return err
}
directory := podInfo.GetDirectory()

// check if this is a shared pod
if podInfo.GetFeed().IsReadOnlyFeed() {
// delete the pod and close if it is opened
Expand All @@ -86,18 +84,15 @@ func (a *API) DeletePod(podName, sessionId string) error {
ui.RemovePodName(podName)
return nil
}

err = directory.RmRootDir(podInfo.GetPodPassword())
if err != nil {
if err != nil && !errors.Is(err, file.ErrFileNotFound) {
return err
}

// delete the pod and close if it is opened
err = ui.GetPod().DeleteOwnPod(podName)
if err != nil {
return err
}

ui.RemovePodName(podName)
return nil
}
Expand Down
22 changes: 16 additions & 6 deletions pkg/dir/inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (d *Directory) GetInode(podPassword, dirNameWithPath string) (*Inode, error
if node != nil {
return node, nil
}
var inode Inode
var data []byte
r, _, err := d.file.Download(utils.CombinePathAndFile(dirNameWithPath, indexFileName), podPassword)
if err != nil { // skipcq: TCV-001
Expand All @@ -79,17 +80,26 @@ func (d *Directory) GetInode(podPassword, dirNameWithPath string) (*Inode, error
if err != nil { // skipcq: TCV-001
return nil, ErrDirectoryNotPresent
}
// TODO remove this and upload to indexfile
err = inode.Unmarshal(data)
if err != nil { // skipcq: TCV-001
return nil, err
}
err = d.SetInode(podPassword, &inode)
if err != nil { // skipcq: TCV-001
return nil, err
}

// ignore delete error
_ = d.fd.DeleteFeedFromTopic(topic, d.getAddress())
} else {
data, err = io.ReadAll(r)
if err != nil { // skipcq: TCV-001
return nil, err
}
}
var inode Inode
err = inode.Unmarshal(data)
if err != nil { // skipcq: TCV-001
return nil, err
err = inode.Unmarshal(data)
if err != nil { // skipcq: TCV-001
return nil, err
}
}
d.AddToDirectoryMap(dirNameWithPath, &inode)
return &inode, nil
Expand Down
2 changes: 0 additions & 2 deletions pkg/dir/rmdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (d *Directory) RmRootDir(podPassword string) error {
if d.GetDirFromDirectoryMap(totalPath) == nil { // skipcq: TCV-001
return ErrDirectoryNotPresent
}

// recursive delete
dirInode := d.GetDirFromDirectoryMap(totalPath)
if dirInode.FileOrDirNames != nil && len(dirInode.FileOrDirNames) > 0 {
Expand Down Expand Up @@ -119,6 +118,5 @@ func (d *Directory) RmRootDir(podPassword string) error {
}
}
}

return d.RemoveInode(podPassword, dirToDelete)
}

0 comments on commit 2b53f73

Please sign in to comment.