Ejemplo n.º 1
0
func moveSimple(fileSpec *Files, flags *MoveFlags, moveType MoveType) (successCount, failedCount int, err error) {

	cleanPattern := cliutils.StripChars(fileSpec.Pattern, "()")
	patternFileName, _ := ioutils.GetFileAndDirFromPath(fileSpec.Pattern)

	regexpPattern := cliutils.PathToRegExp(fileSpec.Pattern)
	placeHolderTarget, err := cliutils.ReformatRegexp(regexpPattern, cleanPattern, fileSpec.Target)
	if err != nil {
		return
	}

	if strings.HasSuffix(placeHolderTarget, "/") {
		placeHolderTarget += patternFileName
	}
	success, err := moveFile(cleanPattern, placeHolderTarget, flags, moveType)
	successCount = cliutils.Bool2Int(success)
	failedCount = cliutils.Bool2Int(!success)
	return
}
Ejemplo n.º 2
0
func moveFiles(regexpPath string, resultItems []AqlSearchResultItem, fileSpec *Files, flags *MoveFlags, moveType MoveType) (successCount, failedCount int, err error) {
	successCount = 0
	failedCount = 0

	for _, v := range resultItems {
		destPathLocal := fileSpec.Target
		isFlat, e := cliutils.StringToBool(fileSpec.Flat, false)
		if e != nil {
			err = e
			return
		}
		if !isFlat {
			if strings.Contains(destPathLocal, "/") {
				file, dir := ioutils.GetFileAndDirFromPath(destPathLocal)
				destPathLocal = cliutils.TrimPath(dir + "/" + v.Path + "/" + file)
			} else {
				destPathLocal = cliutils.TrimPath(destPathLocal + "/" + v.Path + "/")
			}
		}
		destFile, e := cliutils.ReformatRegexp(regexpPath, v.GetFullUrl(), destPathLocal)
		if e != nil {
			err = e
			return
		}
		if strings.HasSuffix(destFile, "/") {
			destFile += v.Name
		}
		success, e := moveFile(v.GetFullUrl(), destFile, flags, moveType)
		if e != nil {
			err = e
			return
		}

		successCount += cliutils.Bool2Int(success)
		failedCount += cliutils.Bool2Int(!success)
	}
	return
}
Ejemplo n.º 3
0
func (b *BoolEnum) SetValue(val bool) {
	b.boolean = booleanEnum(cliutils.Bool2Int(val))
}