Пример #1
0
func (c *Change) checkIndexExistance() (bool, error) {
	var f *File = nil
	if c.Src != nil && c.Src.Id != "" {
		f = c.Src
	} else if c.Dest != nil && c.Dest.Id != "" {
		f = c.Dest
	}

	if f == nil || f.Id == "" {
		return false, nil
	}

	rootPath := c.g.context.AbsPathOf("")
	statResult, statErr := os.Stat(config.IndicesAbsPath(rootPath, f.Id))

	if statErr == nil {
		return statResult != nil, nil
	}

	if !os.IsNotExist(statErr) {
		return false, statErr
	}
	return false, nil
}
Пример #2
0
func (g *Commands) indexAbsPath(fileId string) string {
	return config.IndicesAbsPath(g.context.AbsPathOf(""), fileId)
}
Пример #3
0
func (g *Commands) pruneStaleIndices() (deletions chan *File, err error) {
	var listing chan *File
	indicesDir := config.IndicesAbsPath("", "")
	listing, err = list(g.context, indicesDir, true, nil)

	deletions = make(chan *File)

	if err != nil {
		close(deletions)
		return
	}

	go func() {

		spin := g.playabler()

		defer func() {
			spin.stop()
			close(deletions)
		}()

		queriesPerRequest := 10
		tick := time.Tick(time.Duration(1e9 / queriesPerRequest))

		iterating := true

		doneCount := uint64(0)
		totalDeletions := uint64(0)

		for iterating {
			spin.play()

			localIds := map[string]*File{}
			i := 0
			for i < queriesPerRequest {
				i += 1
				f, ok := <-listing
				if !ok {
					iterating = false
					break
				}

				localIds[f.Name] = f
			}

			if len(localIds) < 1 {
				break
			}

			mapping, mErr := mapifyFiles(g, localIds)
			if mErr != nil {
				g.log.LogErrf("syncIndices: %v\n", mErr)
				continue
			}

			delCount := 0
			for localId, localFile := range localIds {
				_, ok := mapping[localId]
				if !ok {
					delCount += 1
					deletions <- localFile
				}
			}

			doneCount += uint64(i)
			totalDeletions += uint64(delCount)

			spin.pause()
			deletionsReport := ""
			if delCount >= 1 {
				deletionsReport = fmt.Sprintf("%v/%v to be deleted", delCount, i)
			}

			if totalDeletions >= 1 {
				deletionsReport = fmt.Sprintf("%s(%v deletions so far)", deletionsReport, totalDeletions)
			}

			g.log.LogErrf("\rprune: %s %v index items processed so far\r", deletionsReport, doneCount)
			<-tick
		}
	}()

	return
}