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

Added validation at the start of recording. #1612

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

shogo4405
Copy link
Owner

Description & motivation

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Screenshots:

@shogo4405 shogo4405 modified the milestone: 2.0.0 Oct 29, 2024
@shogo4405 shogo4405 added this to the 2.0.0 milestone Oct 29, 2024
outputURL = moviesDirectory.appendingPathComponent(UUID().uuidString).appendingPathExtension(Self.defaultPathExtension)
}

if FileManager.default.fileExists(atPath: outputURL.absoluteString) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be outputURL.path.

self.fileName = fileName ?? UUID().uuidString
self.settings = settings
var outputURL: URL
if let file {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass an URL that represents a file without a path extension (e.g. file:///var/mobile/Containers/Data/Application/7910F2B5-9C52-42CE-87D0-20202839EB58/Documents/Demo ) this logic would result in something like this: file:///var/mobile/Containers/Data/Application/7910F2B5-9C52-42CE-87D0-20202839EB58/Documents/file:///var/mobile/Containers/Data/Application/7910F2B5-9C52-42CE-87D0-20202839EB58/Documents/Demo.mp4, which is an incorrect file path.

A more future-proof suggestion to the file parameter and the outputURL handling:

    if let file {
          if file.hasDirectoryPath {
              outputURL = file.appendingPathComponent(UUID().uuidString)
          } else {
              outputURL = file
          }
          if outputURL.pathExtension == "" {
              outputURL = outputURL.appendingPathExtension(Self.defaultPathExtension)
          }
      } else {
          outputURL = moviesDirectory.appendingPathComponent(UUID().uuidString).appendingPathExtension(Self.defaultPathExtension)
      }

Tested with:

  • URL representing a directory.
  • URL representing a file without extension
  • URL representing a file with extension
  • nil URL

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing it. I’ve also added some test cases on my end. I’m thinking of adding the documentation and then merging.

@shogo4405 shogo4405 force-pushed the featue/advanced-recording branch 2 times, most recently from 0c41c73 to 68caf32 Compare November 1, 2024 14:21
@shogo4405 shogo4405 force-pushed the featue/advanced-recording branch from 68caf32 to 099c48b Compare November 1, 2024 14:49
@shogo4405 shogo4405 merged commit c2c423d into main Nov 1, 2024
2 checks passed
@shogo4405 shogo4405 deleted the featue/advanced-recording branch November 1, 2024 14:57
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

Successfully merging this pull request may close these issues.

2 participants