ChrishonWyllie / Celestial

A Caching service for multimedia
MIT License
8 stars 3 forks source link

Fix uncaught bug where downloaded video files would not override existing ones #75

Closed ChrishonWyllie closed 3 years ago

ChrishonWyllie commented 3 years ago

When a video has been downloaded and ready to be cached to the file system, it first determines if the video should be exported a lower quality.

If not, the downloaded file is expected to be moved from its temporary download location (which is apparently random and provided by URLSession DownloadTask) to a more permanent location.

However, simply moving the file has the unintended possibility of collision. You can't move an item to a URL that already contains an item as evidenced by this error:

Error Domain=NSCocoaErrorDomain Code=516 "{FILE_NAME}"
couldn’t be moved to “{DIRECTORY_NAME}” because an item with the same name already exists." 
UserInfo={NSSourceFilePathErrorKey={FILE_PATH}, NSUserStringVariant=(
    Move
), 
NSDestinationFilePath={DESTINATION_FILE_PATH}, NSFilePath={TEMPORARY_FILE_PATH}, NSUnderlyingError=0x280871860 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

First check if the file exists or delete any files at that path before using the moveItem function

ChrishonWyllie commented 3 years ago

This has been addressed in pull request #78