Example #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())
			}
		}
	}
}
Example #2
0
func (app *App) installPackage(
	packageName string,
	settings config.Settings,
	progressCallback caravel.RetrievalProgressCallback) (err error) {

	remoteDescriptor := app.GetRemoteDescriptor()

	packageURL, err := remoteDescriptor.GetRemoteFileURL(packageName)
	if err != nil {
		return err
	}

	log.Debug("Creating package temp file...")
	packageTempFile, err := ioutil.TempFile(os.TempDir(), packageName)
	if err != nil {
		return err
	}
	packageTempFilePath := packageTempFile.Name()
	log.Debug("Package temp file created '%v'", packageTempFilePath)

	defer func() {
		packageTempFile.Close()

		log.Debug("Deleting package temp file: '%v'", packageTempFilePath)
		tempFileRemovalErr := os.Remove(packageTempFilePath)
		if tempFileRemovalErr != nil {
			log.Warning("Could not remove the package temp file! '%v'", tempFileRemovalErr)
		} else {
			log.Notice("Package temp file removed")
		}
	}()

	log.Info("Retrieving package: %v", packageURL)
	err = caravel.RetrieveChunksFromURL(packageURL, packageTempFile, settings.GetBufferSize(), progressCallback)
	if err != nil {
		return err
	}
	log.Notice("Package retrieved")

	log.Debug("Closing the package temp file...")
	packageTempFile.Close()
	if err != nil {
		return err
	}
	log.Notice("Package temp file closed")

	err = os.MkdirAll(app.filesDirectory, 0700)
	if err != nil {
		return err
	}

	log.Info("Extracting the package. Skipping levels: %v...", remoteDescriptor.GetSkipPackageLevels())
	err = caravel.ExtractZipSkipLevels(packageTempFilePath, app.filesDirectory, remoteDescriptor.GetSkipPackageLevels())
	if err != nil {
		return err
	}
	log.Notice("Package extracted")

	return nil
}
Example #3
0
func initializeLogging(settings config.Settings) {
	log.SetLevel(settings.GetLoggingLevel())

	logsDirectory := settings.GetLogsDirectory()
	log.Debug("Logs directory is: '%v'", logsDirectory)

	tryToRemoveLogs(logsDirectory, settings)
	ensureLogsDirectory(logsDirectory)

	logFile := createLogFile(logsDirectory)

	log.Debug("Now redirecting log lines to file: '%v'", logFile.Name())
	log.Setup(logFile)
}
Example #4
0
func (app *App) Launch(command *exec.Cmd, settings config.Settings, userInterface ui.UserInterface) (err error) {
	log.Info("Starting the app...")

	log.Debug("Hiding the user interface...")
	userInterface.Hide()
	log.Notice("User interface hidden")

	if settings.IsSkipAppOutput() {
		return command.Run()
	}
	var outputBytes []byte
	outputBytes, err = command.CombinedOutput()

	if outputBytes != nil && len(outputBytes) > 0 {
		log.Info("------------------------------")
		log.Info(string(outputBytes))
		log.Info("------------------------------")
	}

	return err
}