Skip to content

Commit

Permalink
move construction of block storage into newVirtualFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Sep 24, 2024
1 parent fab1a45 commit 421925a
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions lib/model/folder_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"log"
"os"
Expand Down Expand Up @@ -78,12 +77,37 @@ func newVirtualFolder(
evLogger events.Logger,
ioLimiter *semaphore.Semaphore,
) service {
return &virtualFolderSyncthingService{

f := &virtualFolderSyncthingService{
folderBase: newFolderBase(cfg, evLogger, model, fset),
blockCache: nil,
backgroundDownloadPending: make(chan struct{}, 1),
backgroundDownloadQueue: *newJobQueue(),
}

blobUrl := ""
virtual_descriptor, hasVirtualDescriptor := strings.CutPrefix(f.Path, ":virtual:")
if hasVirtualDescriptor {
parts := strings.Split(virtual_descriptor, ":mount_at:")
if len(parts) != 2 {
logger.DefaultLogger.Warnf("missing \":mount_at:\" in virtual descriptor")
return nil
}
//url := "s3://bucket-syncthing-uli-virtual-folder-test1/" + myDir
blobUrl = parts[0]
f.mountPath = parts[1]
} else {
myDir := f.Path + "_BlobStorage"
if err := os.MkdirAll(myDir, 0o777); err != nil {
log.Fatal(err)
}
blobUrl = "file://" + myDir + "?no_tmp_dir=yes"
f.mountPath = f.Path + "R"
}

f.blockCache = blockstorage.NewGoCloudUrlStorage(context.TODO(), blobUrl)

return f
}

func (f *virtualFolderSyncthingService) RequestBackgroundDownload(filename string, size int64, modified time.Time) {
Expand Down Expand Up @@ -155,31 +179,6 @@ func (f *virtualFolderSyncthingService) Serve(ctx context.Context) error {

f.ctx = ctx

if f.blockCache == nil {
//f.blockCache = blockstorage.NewGoCloudUrlStorage(ctx, "mem://")

blobUrl := ""
virtual_descriptor, hasVirtualDescriptor := strings.CutPrefix(f.Path, ":virtual:")
if hasVirtualDescriptor {
parts := strings.Split(virtual_descriptor, ":mount_at:")
if len(parts) != 2 {
return errors.New("missing \":mount_at:\" in virtual descriptor")
}
//url := "s3://bucket-syncthing-uli-virtual-folder-test1/" + myDir
blobUrl = parts[0]
f.mountPath = parts[1]
} else {
myDir := f.Path + "_BlobStorage"
if err := os.MkdirAll(myDir, 0o777); err != nil {
log.Fatal(err)
}
blobUrl = "file://" + myDir + "?no_tmp_dir=yes"
f.mountPath = f.Path + "R"
}

f.blockCache = blockstorage.NewGoCloudUrlStorage(ctx, blobUrl)
}

if (f.mountService == nil) && (f.mountPath != "") {
stVF := &syncthingVirtualFolderFuseAdapter{
vFSS: f,
Expand Down

0 comments on commit 421925a

Please sign in to comment.