New functions to get file by path
This commit is contained in:
parent
99975d9df4
commit
b84fe87f48
1 changed files with 22 additions and 0 deletions
|
|
@ -49,6 +49,17 @@ func GetFiles() ([]EFile, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFileByPath(path string) (EFile, error) {
|
||||||
|
path = strings.TrimPrefix(path, FilesDir)
|
||||||
|
|
||||||
|
var f EFile
|
||||||
|
if err := DBQueryRow("SELECT id_file, origin, path, name, cksum, size FROM exercice_files WHERE path = ?", path).Scan(&f.Id, &f.origin, &f.Path, &f.Name, &f.Checksum, &f.Size); err != nil {
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e Exercice) GetFiles() ([]EFile, error) {
|
func (e Exercice) GetFiles() ([]EFile, error) {
|
||||||
if rows, err := DBQuery("SELECT id_file, origin, path, name, cksum, size FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
if rows, err := DBQuery("SELECT id_file, origin, path, name, cksum, size FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -72,6 +83,17 @@ func (e Exercice) GetFiles() ([]EFile, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e Exercice) GetFileByPath(path string) (EFile, error) {
|
||||||
|
path = strings.TrimPrefix(path, FilesDir)
|
||||||
|
|
||||||
|
var f EFile
|
||||||
|
if err := DBQueryRow("SELECT id_file, origin, path, name, cksum, size FROM exercice_files WHERE id_exercice = ? AND path = ?", e.Id, path).Scan(&f.Id, &f.origin, &f.Path, &f.Name, &f.Checksum, &f.Size); err != nil {
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (interface{}, error) {
|
func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (interface{}, error) {
|
||||||
if digest == nil && !OptionalDigest {
|
if digest == nil && !OptionalDigest {
|
||||||
return EFile{}, errors.New("No digest given.")
|
return EFile{}, errors.New("No digest given.")
|
||||||
|
|
|
||||||
Reference in a new issue