in cmd/mount.go [103:187]
func (opt *mountOptions) validate(skipNonEmptyMount bool) error {
if opt.MountPath == "" {
return fmt.Errorf("mount path not provided")
}
if _, err := os.Stat(opt.MountPath); os.IsNotExist(err) {
return fmt.Errorf("mount directory does not exist")
} else if common.IsDirectoryMounted(opt.MountPath) {
// Try to cleanup the stale mount
log.Info("Mount::validate : Mount directory is already mounted, trying to cleanup")
active, err := common.IsMountActive(opt.MountPath)
if active || err != nil {
// Previous mount is still active so we need to fail this mount
return fmt.Errorf("directory is already mounted")
} else {
// Previous mount is in stale state so lets cleanup the state
log.Info("Mount::validate : Cleaning up stale mount")
if err = unmountBlobfuse2(opt.MountPath, true); err != nil {
return fmt.Errorf("directory is already mounted, unmount manually before remount [%v]", err.Error())
}
// Clean up the file-cache temp directory if any
var tempCachePath string
_ = config.UnmarshalKey("file_cache.path", &tempCachePath)
var cleanupOnStart bool
_ = config.UnmarshalKey("file_cache.cleanup-on-start", &cleanupOnStart)
if tempCachePath != "" && cleanupOnStart {
if err = common.TempCacheCleanup(tempCachePath); err != nil {
return fmt.Errorf("failed to cleanup file cache [%s]", err.Error())
}
}
}
} else if !skipNonEmptyMount && !common.IsDirectoryEmpty(opt.MountPath) {
return fmt.Errorf("mount directory is not empty")
}
if err := common.ELogLevel.Parse(opt.Logging.LogLevel); err != nil {
return fmt.Errorf("invalid log level [%s]", err.Error())
}
if opt.DefaultWorkingDir != "" {
common.DefaultWorkDir = opt.DefaultWorkingDir
if opt.Logging.LogFilePath == common.DefaultLogFilePath {
// If default-working-dir is set then default log path shall be set to that path
// Ignore if specific log-path is provided by user
opt.Logging.LogFilePath = filepath.Join(common.DefaultWorkDir, "blobfuse2.log")
}
common.DefaultLogFilePath = filepath.Join(common.DefaultWorkDir, "blobfuse2.log")
}
f, err := os.Stat(common.ExpandPath(common.DefaultWorkDir))
if err == nil && !f.IsDir() {
return fmt.Errorf("default work dir '%s' is not a directory", common.DefaultWorkDir)
}
if err != nil && os.IsNotExist(err) {
// create the default work dir
if err = os.MkdirAll(common.ExpandPath(common.DefaultWorkDir), 0777); err != nil {
return fmt.Errorf("failed to create default work dir [%s]", err.Error())
}
}
opt.Logging.LogFilePath = common.ExpandPath(opt.Logging.LogFilePath)
if !common.DirectoryExists(filepath.Dir(opt.Logging.LogFilePath)) {
err := os.MkdirAll(filepath.Dir(opt.Logging.LogFilePath), os.FileMode(0776)|os.ModeDir)
if err != nil {
return fmt.Errorf("invalid log file path [%s]", err.Error())
}
}
// A user provided value of 0 doesn't make sense for MaxLogFileSize or LogFileCount.
if opt.Logging.MaxLogFileSize == 0 {
opt.Logging.MaxLogFileSize = common.DefaultMaxLogFileSize
}
if opt.Logging.LogFileCount == 0 {
opt.Logging.LogFileCount = common.DefaultLogFileCount
}
return nil
}