Skip to content

Commit

Permalink
intf: movieHash: manage file opening errors properly
Browse files Browse the repository at this point in the history
When failing to open a file to resolve the hash, the interface was
exiting on error because of the assertion. It can happen for a
number of reasons that the file cannot be opened and this should
not prevent TraktForVLC from working properly. This commit aims
at managing the error properly by showing an error message and
aborting the hash resolution.

Relates to #115

Signed-off-by: Raphaël Beamonte <[email protected]>
  • Loading branch information
XaF committed Jun 14, 2018
1 parent 2edebf1 commit f586a1f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions trakt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ end
------------------------------------------------------------------------------
local
function movieHash(fileName)
local fil = assert(io.open(fileName, 'rb'))
local fil, err = io.open(fileName, 'rb')
if not fil then
vlc.msg.err('Error opening file \'' .. fileName .. '\': ' ..
err .. '; media hash will not be resolved.')
return
end
local lo, hi = 0, 0
for i = 1, 8192 do
local a, b, c, d = fil:read(4):byte(1, 4)
Expand Down Expand Up @@ -1912,12 +1917,14 @@ function get_current_info()
loc_cache_changed = true
end

local media_hash, media_size
if cache[infos['key']].uri_proto == 'file' and
(not cache[infos['key']].hash or
not cache[infos['key']].size) then
-- Compute the media hash and size
local media_hash, media_size = movieHash(cache[infos['key']].uri_path)

media_hash, media_size = movieHash(cache[infos['key']].uri_path)
end
if media_hash then
-- Check if any file in the cache matches those information
for k,v in pairs(cache) do
if v.hash == media_hash or v.size == media_size then
Expand Down

0 comments on commit f586a1f

Please sign in to comment.