package dcf import ( "os" "path/filepath" "github.com/shirou/gopsutil/disk" ) func findAllMountPoints() ([]string, error) { mountpoints := []string{} partitions, err := disk.Partitions(false) // physical devices only, so false if err != nil { return nil, err } for _, partition := range partitions { if !contains(mountpoints, partition.Mountpoint) { mountpoints = append(mountpoints, partition.Mountpoint) } } return mountpoints, nil } func findDCFMountPoints() ([]string, error) { filteredMountpoints := []string{} var err error mountpoints, err := findAllMountPoints() if err != nil { return nil, err } for _, mountpoint := range mountpoints { dcimPath := filepath.Join(mountpoint, "DCIM") privatePath := filepath.Join(mountpoint, "PRIVATE") shouldKeep := false if _, err := os.Stat(dcimPath); err == nil { shouldKeep = true } if _, err := os.Stat(privatePath); err == nil { shouldKeep = true } if shouldKeep { filteredMountpoints = append(filteredMountpoints, mountpoint) } } return filteredMountpoints, nil } func contains(slice []string, str string) bool { for _, s := range slice { if s == str { return true } } return false }