Beispiel #1
0
func traverse(gFolder *gdrive.File, lFolder *local.File) error {
	var gFiles []*gdrive.File
	var err error

	for {
		gFiles, err = gFolder.GetFiles()
		if err != nil {
			err = askRetry(err)
			if err != nil {
				return err
			}
		} else {
			break
		}
	}

	lFiles, err := lFolder.GetFiles()
	if err != nil {
		return err
	}

	gMap := makeGDriveNameMap(gFiles)
	lMap := makeLocalNameMap(lFiles)

	for _, lFile := range lFiles {
		gFile, ok := gMap[lFile.Name()]
		if ok {
			matched, err := diffFile(gFile, lFile)
			if err != nil {
				return err
			}
			if !matched {
				fmt.Printf("+-:%s:%s\n", gFile.Path, lFile.Path)
			}

			if lFile.IsDir() {
				err = traverse(gFile, lFile)
				if err != nil {
					return err
				}
			}
		} else {
			fmt.Printf("+ :%s:%s\n", gFolder.Join(lFile.Name()), lFile.Path)
		}
	}
	for _, gFile := range gFiles {
		_, ok := lMap[gFile.Name]
		if !ok {
			fmt.Printf(" -:%s:%s\n", gFile.Path, lFolder.Join(gFile.Name))
		}
	}

	return nil
}
Beispiel #2
0
func diffFile(gFile *gdrive.File, lFile *local.File) (bool, error) {
	if gFile.IsFolder() != lFile.IsDir() {
		return false, nil
	}

	if lFile.IsDir() {
		return true, nil
	}

	md5Checksum, err := lFile.Md5Checksum()
	if err != nil {
		return false, err
	}

	return md5Checksum == gFile.Md5Checksum, nil
}