Cleanup mounts
This commit is contained in:
@@ -101,8 +101,7 @@ func (m *Mount) Mount(ctx context.Context) error {
|
|||||||
mountCtx, cancel := context.WithCancel(ctx)
|
mountCtx, cancel := context.WithCancel(ctx)
|
||||||
m.cancel = cancel
|
m.cancel = cancel
|
||||||
|
|
||||||
configName := fmt.Sprintf("decypharr_%s", m.Provider)
|
if err := setRcloneConfig(m.Provider, m.WebDAVURL); err != nil {
|
||||||
if err := setRcloneConfig(configName, m.WebDAVURL); err != nil {
|
|
||||||
return fmt.Errorf("failed to set rclone config: %w", err)
|
return fmt.Errorf("failed to set rclone config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +119,7 @@ func (m *Mount) Mount(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := m.performMount(mountCtx, mountFn, configName); err != nil {
|
if err := m.performMount(mountCtx, mountFn); err != nil {
|
||||||
m.logger.Error().Err(err).Msgf("Failed to mount %s at %s", m.Provider, m.LocalPath)
|
m.logger.Error().Err(err).Msgf("Failed to mount %s at %s", m.Provider, m.LocalPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -142,9 +141,9 @@ func setRcloneConfig(configName, webdavURL string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mount) performMount(ctx context.Context, mountfn mountlib.MountFn, configName string) error {
|
func (m *Mount) performMount(ctx context.Context, mountfn mountlib.MountFn) error {
|
||||||
// Create filesystem from config
|
// Create filesystem from config
|
||||||
fsrc, err := fs.NewFs(ctx, fmt.Sprintf("%s:", configName))
|
fsrc, err := fs.NewFs(ctx, fmt.Sprintf("%s:", m.Provider))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create filesystem: %w", err)
|
return fmt.Errorf("failed to create filesystem: %w", err)
|
||||||
}
|
}
|
||||||
@@ -153,10 +152,6 @@ func (m *Mount) performMount(ctx context.Context, mountfn mountlib.MountFn, conf
|
|||||||
cfg := configPkg.Get()
|
cfg := configPkg.Get()
|
||||||
rcloneOpt := &cfg.Rclone
|
rcloneOpt := &cfg.Rclone
|
||||||
|
|
||||||
// Parse duration strings
|
|
||||||
dirCacheTime, _ := time.ParseDuration(rcloneOpt.DirCacheTime)
|
|
||||||
attrTimeout, _ := time.ParseDuration(rcloneOpt.AttrTimeout)
|
|
||||||
|
|
||||||
// Parse cache mode
|
// Parse cache mode
|
||||||
var cacheMode vfscommon.CacheMode
|
var cacheMode vfscommon.CacheMode
|
||||||
switch rcloneOpt.VfsCacheMode {
|
switch rcloneOpt.VfsCacheMode {
|
||||||
@@ -175,13 +170,25 @@ func (m *Mount) performMount(ctx context.Context, mountfn mountlib.MountFn, conf
|
|||||||
vfsOpt := &vfscommon.Options{
|
vfsOpt := &vfscommon.Options{
|
||||||
NoModTime: rcloneOpt.NoModTime,
|
NoModTime: rcloneOpt.NoModTime,
|
||||||
NoChecksum: rcloneOpt.NoChecksum,
|
NoChecksum: rcloneOpt.NoChecksum,
|
||||||
DirCacheTime: fs.Duration(dirCacheTime),
|
|
||||||
PollInterval: 0, // Polling is disabled for webdav
|
PollInterval: 0, // Polling is disabled for webdav
|
||||||
CacheMode: cacheMode,
|
CacheMode: cacheMode,
|
||||||
UID: rcloneOpt.UID,
|
UID: rcloneOpt.UID,
|
||||||
GID: rcloneOpt.GID,
|
GID: rcloneOpt.GID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse duration strings
|
||||||
|
if rcloneOpt.DirCacheTime != "" {
|
||||||
|
if dirCacheTime, err := time.ParseDuration(rcloneOpt.DirCacheTime); err == nil {
|
||||||
|
vfsOpt.DirCacheTime = fs.Duration(dirCacheTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rcloneOpt.VfsCacheMaxAge != "" {
|
||||||
|
if vfsCacheMaxAge, err := time.ParseDuration(rcloneOpt.VfsCacheMaxAge); err == nil {
|
||||||
|
vfsOpt.CacheMaxAge = fs.Duration(vfsCacheMaxAge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if rcloneOpt.VfsReadChunkSizeLimit != "" {
|
if rcloneOpt.VfsReadChunkSizeLimit != "" {
|
||||||
var chunkSizeLimit fs.SizeSuffix
|
var chunkSizeLimit fs.SizeSuffix
|
||||||
if err := chunkSizeLimit.Set(rcloneOpt.VfsReadChunkSizeLimit); err == nil {
|
if err := chunkSizeLimit.Set(rcloneOpt.VfsReadChunkSizeLimit); err == nil {
|
||||||
@@ -211,20 +218,32 @@ func (m *Mount) performMount(ctx context.Context, mountfn mountlib.MountFn, conf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rcloneOpt.VfsCacheMaxSize != "" {
|
||||||
|
var cacheMaxSize fs.SizeSuffix
|
||||||
|
if err := cacheMaxSize.Set(rcloneOpt.VfsCacheMaxSize); err == nil {
|
||||||
|
vfsOpt.CacheMaxSize = cacheMaxSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create mount options using global config
|
// Create mount options using global config
|
||||||
mountOpt := &mountlib.Options{
|
mountOpt := &mountlib.Options{
|
||||||
DebugFUSE: false,
|
DebugFUSE: false,
|
||||||
AllowNonEmpty: true,
|
AllowNonEmpty: true,
|
||||||
AllowOther: true,
|
AllowOther: true,
|
||||||
Daemon: false,
|
Daemon: false,
|
||||||
AttrTimeout: fs.Duration(attrTimeout),
|
DeviceName: fmt.Sprintf("decypharr-%s", m.Provider),
|
||||||
DeviceName: fmt.Sprintf("decypharr-%s", configName),
|
VolumeName: fmt.Sprintf("decypharr-%s", m.Provider),
|
||||||
VolumeName: fmt.Sprintf("decypharr-%s", configName),
|
}
|
||||||
|
|
||||||
|
if rcloneOpt.AttrTimeout != "" {
|
||||||
|
if attrTimeout, err := time.ParseDuration(rcloneOpt.AttrTimeout); err == nil {
|
||||||
|
mountOpt.AttrTimeout = fs.Duration(attrTimeout)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set cache dir
|
// Set cache dir
|
||||||
if rcloneOpt.CacheDir != "" {
|
if rcloneOpt.CacheDir != "" {
|
||||||
cacheDir := filepath.Join(rcloneOpt.CacheDir, configName)
|
cacheDir := filepath.Join(rcloneOpt.CacheDir, m.Provider)
|
||||||
if err := os.MkdirAll(cacheDir, 0755); err != nil {
|
if err := os.MkdirAll(cacheDir, 0755); err != nil {
|
||||||
// Log error but continue
|
// Log error but continue
|
||||||
m.logger.Error().Err(err).Msgf("Failed to create cache directory %s, using default cache", cacheDir)
|
m.logger.Error().Err(err).Msgf("Failed to create cache directory %s, using default cache", cacheDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user