예제 #1
0
func tryToRemoveLogs(logsDirectory string, settings config.Settings) {
	if !caravel.DirectoryExists(logsDirectory) {
		return
	}

	logFiles, err := ioutil.ReadDir(logsDirectory)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Cannot list the logs directory: %v\n", err)
		return
	}

	now := time.Now()

	for _, logFile := range logFiles {
		logFileAge := now.Sub(logFile.ModTime())

		if logFileAge.Hours() > float64(settings.GetLogMaxAgeInHours()) {
			logFilePath := filepath.Join(logsDirectory, logFile.Name())
			err = os.Remove(logFilePath)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Cannot delete log file: '%v'\n", logFile.Name())
			}
		}
	}
}
예제 #2
0
func (app *App) PrepareCommand(commandLine []string) (command *exec.Cmd) {
	if caravel.DirectoryExists(app.filesDirectory) {
		os.Chdir(app.filesDirectory)
		log.Notice("Files directory set as the current directory")
	} else {
		os.Chdir(app.Directory)
		log.Notice("App directory set as the current directory")
	}

	if len(commandLine) == 1 {
		return exec.Command(commandLine[0])
	}

	return exec.Command(commandLine[0], commandLine[1:]...)
}
예제 #3
0
func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	if !caravel.DirectoryExists(desktopDir) {
		return fmt.Errorf("Expected desktop dir '%v' not found", desktopDir)
	}

	shortcutFileName := caravel.FormatFileName(referenceDescriptor.GetName()) + ".desktop"
	log.Debug("Shortcut file name: '%v'", shortcutFileName)

	shortcutFilePath := filepath.Join(desktopDir, shortcutFileName)

	log.Info("Creating desktop shortcut: '%v'...", shortcutFilePath)

	shortcutFile, err := os.OpenFile(shortcutFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0700)
	if err != nil {
		return err
	}
	defer func() {
		shortcutFile.Close()
		if err != nil {
			os.Remove(shortcutFilePath)
		}
	}()

	actualIconPath := app.GetActualIconPath(launcher)

	shortcutContent := fmt.Sprintf(linuxShortcutContent,
		referenceDescriptor.GetName(),
		referenceDescriptor.GetDescription(),
		launcher.GetExecutable(),
		app.GetLocalDescriptorPath(),
		actualIconPath)

	_, err = shortcutFile.Write([]byte(shortcutContent))
	if err != nil {
		return err
	}

	log.Notice("Desktop shortcut created")

	return nil
}
예제 #4
0
func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	if !caravel.DirectoryExists(desktopDir) {
		return fmt.Errorf("Expected desktop dir '%v' not found", desktopDir)
	}

	scriptFileName := caravel.FormatFileName(referenceDescriptor.GetName())
	log.Debug("Bash shortcut name: '%v'", scriptFileName)

	scriptFilePath := filepath.Join(desktopDir, scriptFileName)
	log.Info("Creating Bash shortcut: '%v'...", scriptFilePath)

	scriptFile, err := os.OpenFile(scriptFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0700)
	if err != nil {
		return err
	}
	defer func() {
		scriptFile.Close()

		if err != nil {
			os.Remove(scriptFilePath)
		}
	}()

	scriptContent := fmt.Sprintf(macScriptContentFormat,
		launcher.GetExecutable(),
		app.localDescriptorPath)

	_, err = scriptFile.Write([]byte(scriptContent))
	if err != nil {
		return err
	}

	log.Notice("Bash shortcut script created")

	return nil
}
예제 #5
0
func (app *App) DirectoryExists() bool {
	return caravel.DirectoryExists(app.Directory)
}