Skip to content

Commit 3f20813

Browse files
committed
Add s.OpenFile function
1 parent c8ec5cf commit 3f20813

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ func (s *Server) removeFile(tx *sql.Tx, fileUUID string) error {
8686
return nil
8787
}
8888

89+
func (s *Server) OpenFile(fileUUID string) (io.Reader, error) {
90+
// Just to check validity.
91+
_, err := uuid.FromString(fileUUID)
92+
if err != nil {
93+
return nil, errors.Wrap(err, "uuid parse")
94+
}
95+
96+
fileLocation := filepath.Join(s.Conf.StorageDir, fileUUID)
97+
file, err := os.Open(fileLocation)
98+
if err != nil {
99+
if os.IsNotExist(err) {
100+
s.removeFile(nil, fileUUID)
101+
return nil, ErrFileDoesntExists
102+
}
103+
return nil, err
104+
}
105+
return file, nil
106+
}
107+
89108
// GetFile opens file for reading.
90109
//
91110
// Note that access using this function is equivalent to access

0 commit comments

Comments
 (0)