Browse Source

Show warning if annexed content is missing

Don't throw ServerError, instead set the IsAnnexedFile flag and return.
Achilleas Koutsou 6 years ago
parent
commit
de53e00c21
2 changed files with 17 additions and 9 deletions
  1. 9 7
      routes/repo/repo_gin.go
  2. 8 2
      routes/repo/view.go

+ 9 - 7
routes/repo/repo_gin.go

@@ -98,24 +98,26 @@ func calcRepoDOI(c *context.Context, doiBase string) string {
 // the two variables without modifications.
 // the two variables without modifications.
 // Any errors that occur during processing are stored in the provided context.
 // Any errors that occur during processing are stored in the provided context.
 // The FileSize of the annexed content is also saved in the context (c.Data["FileSize"]).
 // The FileSize of the annexed content is also saved in the context (c.Data["FileSize"]).
-func resolveAnnexedContent(c *context.Context, buf []byte, dataRc io.Reader) ([]byte, io.Reader) {
+func resolveAnnexedContent(c *context.Context, buf []byte, dataRc io.Reader) ([]byte, io.Reader, error) {
 	if !tool.IsAnnexedFile(buf) {
 	if !tool.IsAnnexedFile(buf) {
 		// not an annex pointer file; return as is
 		// not an annex pointer file; return as is
-		return buf, dataRc
+		return buf, dataRc, nil
 	}
 	}
 	log.Trace("Annexed file requested: Resolving content for [%s]", bytes.TrimSpace(buf))
 	log.Trace("Annexed file requested: Resolving content for [%s]", bytes.TrimSpace(buf))
 	af, err := gannex.NewAFile(c.Repo.Repository.RepoPath(), "annex", "", buf)
 	af, err := gannex.NewAFile(c.Repo.Repository.RepoPath(), "annex", "", buf)
 	if err != nil {
 	if err != nil {
 		log.Trace("Could not get annex file: %v", err)
 		log.Trace("Could not get annex file: %v", err)
-		c.ServerError("readmeFile.Data", err)
-		return buf, dataRc
+		// c.ServerError("readmeFile.Data", err)
+		c.Data["IsAnnexedFile"] = true
+		return buf, dataRc, err
 	}
 	}
 
 
 	afp, err := af.Open()
 	afp, err := af.Open()
 	if err != nil {
 	if err != nil {
-		c.ServerError("readmeFile.Data", err)
+		// c.ServerError("readmeFile.Data", err)
 		log.Trace("Could not open annex file: %v", err)
 		log.Trace("Could not open annex file: %v", err)
-		return buf, dataRc
+		c.Data["IsAnnexedFile"] = true
+		return buf, dataRc, err
 	}
 	}
 	annexDataReader := bufio.NewReader(afp)
 	annexDataReader := bufio.NewReader(afp)
 	annexBuf := make([]byte, 1024)
 	annexBuf := make([]byte, 1024)
@@ -123,5 +125,5 @@ func resolveAnnexedContent(c *context.Context, buf []byte, dataRc io.Reader) ([]
 	annexBuf = annexBuf[:n]
 	annexBuf = annexBuf[:n]
 	c.Data["FileSize"] = af.Info.Size()
 	c.Data["FileSize"] = af.Info.Size()
 	log.Trace("Annexed file size: %d B", af.Info.Size())
 	log.Trace("Annexed file size: %d B", af.Info.Size())
-	return annexBuf, annexDataReader
+	return annexBuf, annexDataReader, nil
 }
 }

+ 8 - 2
routes/repo/view.go

@@ -86,7 +86,10 @@ func renderDirectory(c *context.Context, treeLink string) {
 		buf = buf[:n]
 		buf = buf[:n]
 
 
 		// GIN mod: Replace existing buf and reader with annexed content buf and reader
 		// GIN mod: Replace existing buf and reader with annexed content buf and reader
-		buf, dataRc = resolveAnnexedContent(c, buf, dataRc)
+		buf, dataRc, err = resolveAnnexedContent(c, buf, dataRc)
+		if err != nil {
+			return
+		}
 
 
 		isTextFile := tool.IsTextFile(buf)
 		isTextFile := tool.IsTextFile(buf)
 		c.Data["IsTextFile"] = isTextFile
 		c.Data["IsTextFile"] = isTextFile
@@ -151,7 +154,10 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 	buf = buf[:n]
 	buf = buf[:n]
 
 
 	// GIN mod: Replace existing buf and reader with annexed content buf and reader
 	// GIN mod: Replace existing buf and reader with annexed content buf and reader
-	buf, dataRc = resolveAnnexedContent(c, buf, dataRc)
+	buf, dataRc, err = resolveAnnexedContent(c, buf, dataRc)
+	if err != nil {
+		return
+	}
 
 
 	isTextFile := tool.IsTextFile(buf)
 	isTextFile := tool.IsTextFile(buf)
 	c.Data["IsTextFile"] = isTextFile
 	c.Data["IsTextFile"] = isTextFile