Kaynağa Gözat

[annex] open empty file

cgars 8 yıl önce
ebeveyn
işleme
9b96b5f1c3
2 değiştirilmiş dosya ile 6 ekleme ve 9 silme
  1. 0 3
      pkg/tool/file.go
  2. 6 6
      routes/repo/view.go

+ 0 - 3
pkg/tool/file.go

@@ -21,9 +21,6 @@ func IsTextFile(data []byte) bool {
 
 func IsAnnexedFile(data []byte) bool {
 	const ANNEXSNIFFSIZE = 5000
-	if len(data) == 0 {
-		return true
-	}
 	if !(len(data) < ANNEXSNIFFSIZE) {
 		data = data[:ANNEXSNIFFSIZE]
 	}

+ 6 - 6
routes/repo/view.go

@@ -143,16 +143,16 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 	c.Data["FileName"] = blob.Name()
 	c.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
 	c.Data["RawFileLink"] = rawLink + "/" + c.Repo.TreePath
-
+	buf := make([]byte, 1024)
 	r, w := io.Pipe()
 	defer r.Close()
 	defer w.Close()
 	go blob.DataPipeline(w, w)
-
-	buf := make([]byte, 1024)
-	n, _ := r.Read(buf)
-	log.Trace("I read %s bytes", n)
-	buf = buf[:n]
+	if blob.Size() > 0 {
+		n, _ := r.Read(buf)
+		log.Trace("I read %s bytes", n)
+		buf = buf[:n]
+	}
 	isannex := tool.IsAnnexedFile(buf)
 
 	var afpR *bufio.Reader