Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortBy/Location not working as configured #125

Open
ztmr opened this issue Oct 8, 2023 · 0 comments
Open

SortBy/Location not working as configured #125

ztmr opened this issue Oct 8, 2023 · 0 comments

Comments

@ztmr
Copy link

ztmr commented Oct 8, 2023

SortBy/Location is not working as configured

Context:

The GetOrder function in pkg/utils/ordering.go is calling the location lookup asynchronously, which means that the location almost always gets added as the last piece of the target path.

The location needs to be resolved upfront (if required) and appended at the right time/order.

  • Camera: all
  • Firmware Version: all
  • Operating System: all
  • Commit ID: 51a4268 (current development branch HEAD)

Expected Behavior:

Default configuration is to sort by date,location,camera so the expected result is to store target files in <date>/<location>/<camera> directory structure.

Current Behavior:

Since the location is resolved asynchronously, the date and camera gets added to the path string first, and location ends up to be the latest almost in all the cases.

I've made a quick and dirty hack to to prove this issue and it works fine with the following code:

func GetOrder(sortoptions SortOptions, GetLocation locationUtil, osPathname, out, mediaDate, deviceName string) string {
  order := orderFromConfig()
  dayFolder := out

  var wg sync.WaitGroup

  location := fallbackFromConfig()

  for _, item := range order {
    switch item {
    case "location":
      if GetLocation == nil {
        continue
      }
      wg.Add(1)
      go func() {
        defer wg.Done()
        locationFromFile, locerr := GetLocation.GetLocation(osPathname)
        if locerr == nil {
          reverseLocation, reverseerr := ReverseLocation(*locationFromFile)
          if reverseerr == nil {
            location = reverseLocation
            if location == "" || location == " " {
              location = fallbackFromConfig()
            }
          }
        }
      }()
    default:
    }
  }

  wg.Wait()

  for _, item := range order {
    switch item {
    case "date":
      dayFolder = filepath.Join(dayFolder, mediaDate)
    case "camera":
      if sortoptions.ByCamera {
        dayFolder = filepath.Join(dayFolder, deviceName)
      }
    case "location":
      if sortoptions.ByLocation {
        dayFolder = filepath.Join(dayFolder, location)
      }

    default:
      // Not supported
    }
  }

  if _, err := os.Stat(dayFolder); os.IsNotExist(err) {
    _ = os.MkdirAll(dayFolder, 0o755)
  }
  return dayFolder
}

Logs / Screenshots:

N/A

Steps to Reproduce:

Default configuration. No need to change anything, just run import on any camera.

ztmr added a commit to ztmr/mmt that referenced this issue Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant