-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Conversation
outputURL = moviesDirectory.appendingPathComponent(UUID().uuidString).appendingPathExtension(Self.defaultPathExtension) | ||
} | ||
|
||
if FileManager.default.fileExists(atPath: outputURL.absoluteString) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
0c41c73
to
68caf32
Compare
68caf32
to
099c48b
Compare
Description & motivation
Type of change
Screenshots: