func AppFilesInDir(dir string) (appFiles []models.AppFileFields, err error) { dir, err = filepath.Abs(dir) if err != nil { return } err = WalkAppFiles(dir, func(fileName string, fullPath string) (err error) { fileInfo, err := os.Lstat(fullPath) if err != nil { return } appFile := models.AppFileFields{ Path: filepath.ToSlash(fileName), Size: fileInfo.Size(), } if fileInfo.IsDir() { appFile.Sha1 = "0" appFile.Size = 0 } else { hash := sha1.New() err = fileutils.CopyPathToWriter(fullPath, hash) if err != nil { return } appFile.Sha1 = fmt.Sprintf("%x", hash.Sum(nil)) } appFiles = append(appFiles, appFile) return }) return }
func (appfiles ApplicationFiles) AppFilesInDir(dir string) (appFiles []models.AppFileFields, err error) { dir, err = filepath.Abs(dir) if err != nil { return } err = appfiles.WalkAppFiles(dir, func(fileName string, fullPath string) error { fileInfo, err := os.Lstat(fullPath) if err != nil { return err } appFile := models.AppFileFields{ Path: filepath.ToSlash(fileName), Size: fileInfo.Size(), } if fileInfo.IsDir() { appFile.Sha1 = "0" appFile.Size = 0 } else { hash := sha1.New() file, err := os.Open(fullPath) if err != nil { return err } defer file.Close() _, err = io.Copy(hash, file) if err != nil { return err } appFile.Sha1 = fmt.Sprintf("%x", hash.Sum(nil)) } appFiles = append(appFiles, appFile) return nil }) return }
func (appfiles ApplicationFiles) AppFilesInDir(dir string) ([]models.AppFileFields, error) { appFiles := []models.AppFileFields{} fullDirPath, toplevelErr := filepath.Abs(dir) if toplevelErr != nil { return appFiles, toplevelErr } toplevelErr = appfiles.WalkAppFiles(fullDirPath, func(fileName string, fullPath string) error { fileInfo, err := os.Lstat(fullPath) if err != nil { return err } appFile := models.AppFileFields{ Path: filepath.ToSlash(fileName), Size: fileInfo.Size(), } if fileInfo.IsDir() { appFile.Sha1 = "0" appFile.Size = 0 } else { sha, err := appfiles.shaFile(fullPath) if err != nil { return err } appFile.Sha1 = sha } appFiles = append(appFiles, appFile) return nil }) return appFiles, toplevelErr }