Prechádzať zdrojové kódy

Changed structure to internal

luis 7 rokov pred
rodič
commit
f9b411c17d

+ 0 - 35
fs/gdrivefs/gdrivefs.go.bak

@@ -1,35 +0,0 @@
-package gdrivefs
-
-import (
-	"dev.hexasoftware.com/hxs/cloudmount/cloudfs"
-	"github.com/jacobsa/fuse/fuseutil"
-	drive "google.golang.org/api/drive/v3"
-)
-
-// Driver for gdrive
-type GDriveDriver struct {
-	core *cloudfs.Core
-
-	fuseHandler *FuseHandler
-	driveClient *drive.Service
-}
-
-func New() cloudfs.Driver {
-	return &GDriveDriver{}
-
-}
-
-func (d *GDriveDriver) Init(core *cloudfs.Core) {
-	d.core = core
-	d.driveClient = d.GetDriveService()
-}
-
-func (d *GDriveDriver) Refresh() {
-
-}
-
-func (d *GDriveDriver) FuseHandler() fuseutil.FileSystem {
-
-	return NewFuseHandler(d)
-
-}

+ 1 - 1
cloudfs/config.go

@@ -1,4 +1,4 @@
-package cloudfs
+package core
 
 // Config struct
 type Config struct {

+ 1 - 1
cloudfs/core.go

@@ -1,4 +1,4 @@
-package cloudfs
+package core
 
 import (
 	"context"

+ 1 - 1
cloudfs/driver.go

@@ -1,4 +1,4 @@
-package cloudfs
+package core
 
 import "github.com/jacobsa/fuse/fuseutil"
 

fs/gdrivefs/client.go → internal/fs/gdrivefs/client.go


+ 77 - 0
internal/fs/gdrivefs/file_container.go

@@ -0,0 +1,77 @@
+package gdrivefs
+
+import (
+	"sync"
+
+	"github.com/jacobsa/fuse/fuseops"
+)
+
+type FileContainer struct {
+	fileEntries map[fuseops.InodeID]*FileEntry
+	tree        *FileEntry
+	fs          *GDriveFS
+	uid         uint32
+	gid         uint32
+
+	inodeMU *sync.Mutex
+}
+
+func NewFileContainer(fs *GDriveFS) *FileContainer {
+	fc := &FileContainer{
+		fileEntries: map[fuseops.InodeID]*FileEntry{},
+		fs:          fs,
+		inodeMU:     &sync.Mutex{},
+	}
+	fc.tree = fc.FileEntry(fuseops.RootInodeID)
+	return fc
+}
+
+func (fc *FileContainer) FindByInode(inode fuseops.InodeID) *FileEntry {
+	return fc.fileEntries[inode]
+}
+
+//Return or create inode
+func (fc *FileContainer) FileEntry(inodeOps ...fuseops.InodeID) *FileEntry {
+
+	fc.inodeMU.Lock()
+	defer fc.inodeMU.Unlock()
+
+	var inode fuseops.InodeID
+	if len(inodeOps) > 0 {
+		inode = inodeOps[0]
+		if fe, ok := fc.fileEntries[inode]; ok {
+			return fe
+		}
+	} else { // generate new inode
+		// Max Inode Number
+		for inode = 2; inode < 99999; inode++ {
+			_, ok := fc.fileEntries[inode]
+			if !ok {
+				break
+			}
+		}
+	}
+
+	fe := &FileEntry{
+		Inode:     inode,
+		container: fc,
+		//fs:        fc.fs,
+		children: []*FileEntry{},
+		Attr:     fuseops.InodeAttributes{},
+	}
+	fc.fileEntries[inode] = fe
+
+	return fe
+}
+
+// RemoveEntry remove file entry
+func (fc *FileContainer) RemoveEntry(entry *FileEntry) {
+	var inode fuseops.InodeID
+	for k, e := range fc.fileEntries {
+		if e == entry {
+			inode = k
+		}
+	}
+	delete(fc.fileEntries, inode)
+
+}

+ 0 - 71
fs/gdrivefs/fileentry.go

@@ -8,83 +8,12 @@ import (
 	"net/http"
 	"os"
 	"strings"
-	"sync"
 	"time"
 
 	"github.com/jacobsa/fuse/fuseops"
 	drive "google.golang.org/api/drive/v3"
 )
 
-type FileContainer struct {
-	fileEntries map[fuseops.InodeID]*FileEntry
-	tree        *FileEntry
-	fs          *GDriveFS
-	uid         uint32
-	gid         uint32
-
-	inodeMU *sync.Mutex
-}
-
-func NewFileContainer(fs *GDriveFS) *FileContainer {
-	fc := &FileContainer{
-		fileEntries: map[fuseops.InodeID]*FileEntry{},
-		fs:          fs,
-		inodeMU:     &sync.Mutex{},
-	}
-	fc.tree = fc.FileEntry(fuseops.RootInodeID)
-	return fc
-}
-
-func (fc *FileContainer) FindByInode(inode fuseops.InodeID) *FileEntry {
-	return fc.fileEntries[inode]
-}
-
-//Return or create inode
-func (fc *FileContainer) FileEntry(inodeOps ...fuseops.InodeID) *FileEntry {
-
-	fc.inodeMU.Lock()
-	defer fc.inodeMU.Unlock()
-
-	var inode fuseops.InodeID
-	if len(inodeOps) > 0 {
-		inode = inodeOps[0]
-		if fe, ok := fc.fileEntries[inode]; ok {
-			return fe
-		}
-	} else { // generate new inode
-		// Max Inode Number
-		for inode = 2; inode < 99999; inode++ {
-			_, ok := fc.fileEntries[inode]
-			if !ok {
-				break
-			}
-		}
-	}
-
-	fe := &FileEntry{
-		Inode:     inode,
-		container: fc,
-		//fs:        fc.fs,
-		children: []*FileEntry{},
-		Attr:     fuseops.InodeAttributes{},
-	}
-	fc.fileEntries[inode] = fe
-
-	return fe
-}
-
-// RemoveEntry remove file entry
-func (fc *FileContainer) RemoveEntry(entry *FileEntry) {
-	var inode fuseops.InodeID
-	for k, e := range fc.fileEntries {
-		if e == entry {
-			inode = k
-		}
-	}
-	delete(fc.fileEntries, inode)
-
-}
-
 //FileEntry entry to handle files
 type FileEntry struct {
 	//parent *FileEntry

+ 3 - 3
fs/gdrivefs/gdrivefs.go

@@ -8,7 +8,7 @@ import (
 	"syscall"
 	"time"
 
-	"dev.hexasoftware.com/hxs/cloudmount/cloudfs"
+	"dev.hexasoftware.com/hxs/cloudmount/internal/core"
 	"dev.hexasoftware.com/hxs/prettylog"
 
 	"golang.org/x/net/context"
@@ -37,7 +37,7 @@ type Handle struct {
 type GDriveFS struct {
 	fuseutil.NotImplementedFileSystem // Defaults
 
-	core   *cloudfs.Core // Core Config instead?
+	core   *core.Core // Core Config instead?
 	client *drive.Service
 	//root   *FileEntry // hiearchy reference
 	root *FileContainer
@@ -52,7 +52,7 @@ type GDriveFS struct {
 	// Map IDS with FileEntries
 }
 
-func New(core *cloudfs.Core) cloudfs.Driver {
+func New(core *core.Core) core.Driver {
 
 	fs := &GDriveFS{
 		core:        core,

+ 7 - 5
main.go

@@ -13,8 +13,8 @@ import (
 
 	"dev.hexasoftware.com/hxs/prettylog"
 
-	"dev.hexasoftware.com/hxs/cloudmount/cloudfs"
-	"dev.hexasoftware.com/hxs/cloudmount/fs/gdrivefs"
+	"dev.hexasoftware.com/hxs/cloudmount/internal/core"
+	"dev.hexasoftware.com/hxs/cloudmount/internal/fs/gdrivefs"
 )
 
 var (
@@ -29,7 +29,7 @@ func main() {
 	// getClient
 	fmt.Printf("%s-%s\n", Name, Version)
 
-	core := cloudfs.New()
+	core := core.New()
 	core.Drivers["gdrive"] = gdrivefs.New
 
 	err := core.Init()
@@ -51,8 +51,10 @@ func main() {
 		}
 
 		cmd := exec.Command(os.Args[0], subArgs...)
-		cmd.Stdout = os.Stdout
-		cmd.Stderr = os.Stderr
+		if core.Config.VerboseLog {
+			cmd.Stdout = os.Stdout
+			cmd.Stderr = os.Stderr
+		}
 		cmd.Start()
 		fmt.Println("[PID]", cmd.Process.Pid)
 		os.Exit(0)

BIN
test/cloudmount