shithub: cuefs

Download patch

ref: 55bd2aa0f91dbbd025529b78db456ce68320fdd9
parent: 8e5da639758f408f3fdaf0047848c2d6a625aa97
author: Tevo <estevan.cps@gmail.com>
date: Sun Feb 14 19:13:20 EST 2021

Properly check if flacseek succeeded

--- a/BUGS
+++ b/BUGS
@@ -14,3 +14,4 @@
 	it probably wouldn't hurt to try parsing some of those; not a high priority at the moment
 • cuefs does not respect PREGAP and POSTGAP tags on cuesheets
 • zuke's mkplist dislikes cuefs, somehow (trying to mkplist on a cuefs mountpoint doesn't even generate 9p rpcs, something's really wrong)
+• we likely don't handle "syntatically valid but semantically invalid" cuesheets very well
--- a/fs.c
+++ b/fs.c
@@ -476,7 +476,7 @@
 	if(offset < enc->curoff)
 	{
 		debug("seekflac: tried to seek to %lld but we're on %lld, refusing\n", offset, enc->curoff);
-		return enc->curoff;
+		return -1;
 	}
 
 	debug("seekflac: %lld → %lld\n", enc->curoff, offset);
@@ -503,7 +503,17 @@
 	}
 
 	if(enc->curoff != r->ifcall.offset)
-		seekflac(enc, r->ifcall.offset);
+	if(seekflac(enc, r->ifcall.offset) < 0)
+	{
+		debug("flacserve: cannot seek, discarding decoder and retrying\n");
+		closeflac(enc);
+		enc = r->fid->aux = flacenc(e);
+		if(seekflac(enc, r->ifcall.offset) < 0)
+		{
+			respond(r, "cannot seek");
+			return;
+		}
+	}
 
 	r->ofcall.count = readflac(enc, r->ofcall.data, r->ifcall.count);
 	respond(r, nil);