Example #1
0
func (app *App) GetLocalDescriptor() (localDescriptor descriptors.AppDescriptor) {
	if app.localDescriptorCached {
		return app.localDescriptor
	}

	app.localDescriptorCached = true

	if !caravel.FileExists(app.localDescriptorPath) {
		log.Notice("The local descriptor is missing")
		return nil
	}

	log.Notice("The local descriptor has been found! Opening it...")
	localDescriptor, err := descriptors.NewAppDescriptorFromPath(app.localDescriptorPath)
	if err != nil {
		log.Warning(err.Error())
		return nil
	}
	log.Notice("Local descriptor ready")

	log.Debug("The local descriptor is: %#v", localDescriptor)

	app.localDescriptor = localDescriptor

	return localDescriptor
}
Example #2
0
func getRawMoonSettings() (rawMoonSettings *rawMoonSettingsStruct) {
	rawMoonSettings = &rawMoonSettingsStruct{
		BackgroundColor:  -1,
		ForegroundColor:  -1,
		LogMaxAgeInHours: defaultLogMaxAgeInHours,
	}

	userDir, err := caravel.GetUserDirectory()
	if err != nil {
		return rawMoonSettings
	}

	userSettingsPath := filepath.Join(userDir, userSettingsFileName)
	if !caravel.FileExists(userSettingsPath) {
		return rawMoonSettings
	}

	rawSettingsBytes, err := ioutil.ReadFile(userSettingsPath)
	if err != nil {
		return rawMoonSettings
	}

	err = json.Unmarshal(rawSettingsBytes, rawMoonSettings)
	if err != nil {
		return &rawMoonSettingsStruct{}
	}

	log.Debug("Settings file content: %#v", rawMoonSettings)

	return rawMoonSettings
}
Example #3
0
func (app *App) UnlockDirectory() (err error) {
	if app.lockFile == nil {
		return nil
	}

	if !caravel.FileExists(app.lockFile.Name()) {
		return nil
	}

	log.Info("Releasing the API lock...")
	err = lockapi.UnlockFile(app.lockFile)
	if err != nil {
		return err
	}
	log.Notice("Lock released")

	log.Info("Closing lock file...")
	err = app.lockFile.Close()
	if err != nil {
		return err
	}
	log.Notice("Lock file closed")

	log.Info("Deleting lock file...")
	err = os.Remove(app.lockFile.Name())
	if err != nil {
		return err
	}
	log.Notice("Lock file deleted")

	app.lockFile = nil

	return nil
}
Example #4
0
func (app *App) CheckFiles(
	settings config.Settings,
	userInterface ui.UserInterface) (err error) {

	localDescriptor := app.GetLocalDescriptor()
	remoteDescriptor := app.GetRemoteDescriptor()

	if remoteDescriptor == nil {
		log.Notice("Skipping file check, as the remote descriptor is missing")
		return nil
	}

	userInterface.SetHeader("Checking the app files")
	log.Notice("Computing differences...")

	packagesToUpdate := app.getPackagesToUpdate()

	if len(packagesToUpdate) == 0 {
		log.Notice("All the packages are up-to-date")
		return nil
	}

	if localDescriptor != nil && caravel.FileExists(app.GetLocalDescriptorPath()) {
		log.Info("Deleting the local descriptor before starting the update process...")
		err = os.Remove(app.GetLocalDescriptorPath())
		if err != nil {
			return err
		}
		log.Notice("Local descriptor deleted")
	}

	retrieveAllPackages := (len(packagesToUpdate) == len(remoteDescriptor.GetPackageVersions()))
	log.Notice("Must retrieve all the remote packages? %v", retrieveAllPackages)

	if retrieveAllPackages {
		log.Info("Removing app files dir...")
		err = os.RemoveAll(app.filesDirectory)
		if err != nil {
			return err
		}
		log.Notice("App files dir removed")
	}

	for packageIndex, packageName := range packagesToUpdate {
		userInterface.SetHeader(
			fmt.Sprintf("Updating package %v of %v: %v",
				packageIndex+1,
				len(packagesToUpdate),
				packageName))

		log.Notice("Downloading %v...", packageName)

		err = app.installPackage(
			packageName,
			settings,
			func(retrievedSize int64, totalSize int64) {
				log.Notice("Retrieved: %v / %v bytes", retrievedSize, totalSize)
				userInterface.SetProgress(float64(retrievedSize) / float64(totalSize))
			})
		if err != nil {
			return err
		}
	}

	log.Notice("App files checked")
	return nil
}