Commit d245fcb5 authored by ale's avatar ale

Do not call os.Open directly but use FileStorage.Open

parent e26a7a72
Pipeline #827 passed with stages
in 1 minute and 19 seconds
......@@ -4,7 +4,6 @@ import (
"encoding/xml"
"errors"
"io"
"os"
"path/filepath"
"strings"
)
......@@ -67,8 +66,8 @@ func opfParse(r io.Reader) (*Metadata, error) {
return opf.Meta.ToMetadata(), nil
}
func opfOpen(path string) (*Metadata, error) {
file, err := os.Open(path)
func opfOpen(storage *FileStorage, path string) (*Metadata, error) {
file, err := storage.Open(path)
if err != nil {
return nil, err
}
......@@ -88,7 +87,7 @@ func (p *opfProvider) Lookup(storage *FileStorage, path, filetype string) (*Meta
replaceExt(path, ".opf"),
}
for _, opfpath := range paths {
if m, err := opfOpen(storage.Abs(opfpath)); err == nil {
if m, err := opfOpen(storage, opfpath); err == nil {
return m, err
}
}
......
......@@ -9,7 +9,6 @@ import (
"mime/multipart"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"sync"
......@@ -91,8 +90,8 @@ func (r *remoteServer) DiffRequest(diffreq *diffRequest) (*diffResponse, error)
return &diffresp, nil
}
func addFilePart(w *multipart.Writer, varname, filename, mimeFilename string) error {
file, err := os.Open(filename)
func addFilePart(w *multipart.Writer, varname string, storage *FileStorage, filename, mimeFilename string) error {
file, err := storage.Open(filename)
if err != nil {
return err
}
......@@ -128,14 +127,14 @@ func (r *remoteServer) SendBook(book *Book, storage *FileStorage, files []*File)
for i, f := range files {
varname := fmt.Sprintf("book%d", i)
filename := fmt.Sprintf("%d%s", book.Id, f.FileType)
if err := addFilePart(w, varname, storage.Abs(f.Path), filename); err != nil {
if err := addFilePart(w, varname, storage, f.Path, filename); err != nil {
w.Close()
return err
}
}
if book.CoverPath != "" {
if err := addFilePart(w, "cover", storage.Abs(book.CoverPath), "cover.jpg"); err != nil {
if err := addFilePart(w, "cover", storage, book.CoverPath, "cover.jpg"); err != nil {
w.Close()
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment