Skip to content

Commit

Permalink
Merge pull request Place1#7 from vincentbitter/Path-issues
Browse files Browse the repository at this point in the history
Path issues
  • Loading branch information
Place1 authored Dec 10, 2019
2 parents 4c89f9a + 4883ae0 commit 271f737
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/services/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services

import (
"fmt"
"os"
"net"
"sync"
"time"
Expand Down Expand Up @@ -67,7 +68,11 @@ func (d *DeviceManager) AddDevice(user string, name string, publicKey string) (*
}

func (d *DeviceManager) ListDevices(user string) ([]*storage.Device, error) {
return d.storage.List(user + "/")
prefix := ""
if (user != "") {
prefix = user + string(os.PathSeparator)
}
return d.storage.List(prefix)
}

func (d *DeviceManager) DeleteDevice(user string, name string) error {
Expand Down
4 changes: 4 additions & 0 deletions internal/storage/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *DiskStorage) List(prefix string) ([]*Device, error) {
return nil
}
p := strings.TrimPrefix(path, s.directory)
p = strings.TrimPrefix(p, string(os.PathSeparator))
if strings.HasPrefix(p, prefix) {
files = append(files, path)
}
Expand All @@ -58,6 +59,8 @@ func (s *DiskStorage) List(prefix string) ([]*Device, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to list storage directory")
}
logrus.Debugf("Found files: %+v", files)

devices := []*Device{}
for _, file := range files {
bytes, err := ioutil.ReadFile(file)
Expand All @@ -73,6 +76,7 @@ func (s *DiskStorage) List(prefix string) ([]*Device, error) {
}
devices = append(devices, device)
}
logrus.Debugf("Found devices: %+v", devices)
return devices, nil
}

Expand Down

0 comments on commit 271f737

Please sign in to comment.