|
@@ -83,6 +83,7 @@ type FileSystemAbstraction interface {
|
|
|
WriteStream(string, io.Reader, os.FileMode) error
|
|
|
ReadStream(string) (io.ReadCloser, error)
|
|
|
Walk(string, filepath.WalkFunc) error
|
|
|
+ Heartbeat() error
|
|
|
}
|
|
|
|
|
|
//System Handler for returing
|
|
@@ -99,6 +100,7 @@ type FileSystemHandler struct {
|
|
|
FilesystemDatabase *db.Database
|
|
|
FileSystemAbstraction FileSystemAbstraction
|
|
|
Filesystem string
|
|
|
+ StartOptions FileSystemOption
|
|
|
Closed bool
|
|
|
}
|
|
|
|
|
@@ -171,6 +173,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
|
|
|
FilesystemDatabase: fsdb,
|
|
|
FileSystemAbstraction: localfs.NewLocalFileSystemAbstraction(option.Uuid, rootpath, option.Hierarchy, option.Access == arozfs.FsReadOnly),
|
|
|
Filesystem: fstype,
|
|
|
+ StartOptions: option,
|
|
|
Closed: false,
|
|
|
}, nil
|
|
|
|
|
@@ -196,6 +199,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
|
|
|
FilesystemDatabase: nil,
|
|
|
FileSystemAbstraction: webdavfs,
|
|
|
Filesystem: fstype,
|
|
|
+ StartOptions: option,
|
|
|
Closed: false,
|
|
|
}, nil
|
|
|
} else if fstype == "smb" {
|
|
@@ -208,12 +212,19 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
|
|
|
rootShare := pathChunks[1]
|
|
|
user := option.Username
|
|
|
password := option.Password
|
|
|
-
|
|
|
- smbfs, err := smbfs.NewServerMessageBlockFileSystemAbstraction(option.Uuid, option.Hierarchy, ipAddr, rootShare, user, password)
|
|
|
+ smbfs, err := smbfs.NewServerMessageBlockFileSystemAbstraction(
|
|
|
+ option.Uuid,
|
|
|
+ option.Hierarchy,
|
|
|
+ ipAddr,
|
|
|
+ rootShare,
|
|
|
+ user,
|
|
|
+ password,
|
|
|
+ )
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- return &FileSystemHandler{
|
|
|
+
|
|
|
+ thisFsh := FileSystemHandler{
|
|
|
Name: option.Name,
|
|
|
UUID: option.Uuid,
|
|
|
Path: option.Path,
|
|
@@ -225,8 +236,11 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
|
|
|
FilesystemDatabase: nil,
|
|
|
FileSystemAbstraction: smbfs,
|
|
|
Filesystem: fstype,
|
|
|
+ StartOptions: option,
|
|
|
Closed: false,
|
|
|
- }, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return &thisFsh, nil
|
|
|
} else if fstype == "ftp" {
|
|
|
|
|
|
ftpfs, err := ftpfs.NewFTPFSAbstraction(option.Uuid, option.Hierarchy, option.Path, option.Username, option.Password)
|
|
@@ -245,6 +259,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
|
|
|
FilesystemDatabase: nil,
|
|
|
FileSystemAbstraction: ftpfs,
|
|
|
Filesystem: fstype,
|
|
|
+ StartOptions: option,
|
|
|
Closed: false,
|
|
|
}, nil
|
|
|
|
|
@@ -382,6 +397,31 @@ func (fsh *FileSystemHandler) DeleteFileRecord(rpath string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+//Reload the target file system abstraction
|
|
|
+func (fsh *FileSystemHandler) ReloadFileSystelAbstraction() error {
|
|
|
+ log.Println("[File System] Reloading File System Abstraction for " + fsh.Name)
|
|
|
+ //Load the start option for this fsh
|
|
|
+ originalStartOption := fsh.StartOptions
|
|
|
+
|
|
|
+ //Close the file system handler
|
|
|
+ fsh.Close()
|
|
|
+
|
|
|
+ //Give it a few ms to do physical disk stuffs
|
|
|
+ time.Sleep(100 * time.Millisecond)
|
|
|
+
|
|
|
+ //Generate a new fsh from original start option
|
|
|
+ reloadedFsh, err := NewFileSystemHandler(originalStartOption)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ //Overwrite the pointers to target fsa
|
|
|
+ fsh.FileSystemAbstraction = reloadedFsh.FileSystemAbstraction
|
|
|
+ fsh.FilesystemDatabase = reloadedFsh.FilesystemDatabase
|
|
|
+ fsh.Closed = false
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
//Close an openeded File System
|
|
|
func (fsh *FileSystemHandler) Close() {
|
|
|
//Set the close flag to true so others function wont access it
|