diff --git a/src/building.go b/src/building.go index dab0a7aa..07c3735c 100644 --- a/src/building.go +++ b/src/building.go @@ -1,3 +1,5 @@ +// functions for post, thread, board, and page building + package main import ( diff --git a/src/posting.go b/src/posting.go index 47097ab4..dc1af985 100755 --- a/src/posting.go +++ b/src/posting.go @@ -1,4 +1,4 @@ -// functions for handling posting, uploading, and post/thread/board page building +// functions for handling posting, uploading, and bans package main @@ -401,7 +401,7 @@ func makePost(writer http.ResponseWriter, request *http.Request) { thumbPath := path.Join(config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "t."+thumbFiletype, -1)) catalogThumbPath := path.Join(config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "c."+thumbFiletype, -1)) - if err := ioutil.WriteFile(filePath, data, 0777); err != nil { + if err = ioutil.WriteFile(filePath, data, 0777); err != nil { handleError(0, "Couldn't write file \""+post.Filename+"\""+err.Error()) serveErrorPage(writer, "Couldn't write file \""+post.FilenameOriginal+"\"") return @@ -451,7 +451,7 @@ func makePost(writer http.ResponseWriter, request *http.Request) { serveErrorPage(writer, handleError(1, "Error getting video info: "+err.Error())) return } - if err == nil && outputBytes != nil { + if outputBytes != nil { outputStringArr := strings.Split(string(outputBytes), "\n") for _, line := range outputStringArr { lineArr := strings.Split(line, "=") @@ -574,16 +574,16 @@ func makePost(writer http.ResponseWriter, request *http.Request) { boards, _ := getBoardArr(nil, "") if isBanned(banStatus, boards[post.BoardID-1].Dir) { - var banpage_buffer bytes.Buffer - var banpage_html string - banpage_buffer.Write([]byte("")) - if err = banpage_tmpl.Execute(&banpage_buffer, map[string]interface{}{ + var banpageBuffer bytes.Buffer + + banpageBuffer.Write([]byte("")) + if err = banpage_tmpl.Execute(&banpageBuffer, map[string]interface{}{ "config": config, "ban": banStatus, "banBoards": boards[post.BoardID-1].Dir, }); err != nil { - fmt.Fprintf(writer, banpage_html+handleError(1, err.Error())+"\n\n") + fmt.Fprintf(writer, handleError(1, err.Error())) return } - fmt.Fprintf(writer, banpage_buffer.String()) + fmt.Fprintf(writer, banpageBuffer.String()) return } diff --git a/src/version.go b/src/version.go new file mode 100644 index 00000000..d8ac1802 --- /dev/null +++ b/src/version.go @@ -0,0 +1,55 @@ +package main + +import ( + "fmt" +) + +type GochanVersion struct { + Major uint + Minor uint + Revision uint + Extra string +} + +func ParseVersion(vStr string) GochanVersion { + var v GochanVersion + fmt.Sscanf(vStr, "%d.%d.%d-%s", &v.Major, &v.Minor, &v.Revision, &v.Extra) + return v +} + +func (v *GochanVersion) Compare(v2 GochanVersion) int { + if v.Major > v2.Major { + return 1 + } + if v.Major < v2.Major { + return -1 + } + if v.Minor > v2.Minor { + return 1 + } + if v.Minor < v2.Minor { + return -1 + } + if v.Revision > v2.Revision { + return 1 + } + if v.Revision < v2.Revision { + return -1 + } + return 0 +} + +func (v *GochanVersion) CompareString(v2 string) int { + return v.Compare(ParseVersion(v2)) +} + +func (v *GochanVersion) String() string { + str := fmt.Sprintf("%d.%d", v.Major, v.Minor) + if v.Revision > 0 { + str += fmt.Sprintf(".%d", v.Revision) + } + if v.Extra != "" { + str += "-" + v.Extra + } + return str +}