sync: add dependency on flag to download file
This commit is contained in:
parent
dcfb34c6fd
commit
1e2a74f3ca
9 changed files with 112 additions and 16 deletions
|
@ -84,6 +84,15 @@ func GetFileByPath(path string) (EFile, error) {
|
|||
return f, nil
|
||||
}
|
||||
|
||||
// GetFileByFilename retrieves the file that should be called so.
|
||||
func (e Exercice) GetFileByFilename(filename string) (f EFile, err error) {
|
||||
filename = path.Base(filename)
|
||||
|
||||
err = DBQueryRow("SELECT id_file, origin, path, id_exercice, name, cksum, size FROM exercice_files WHERE id_exercice = ? AND origin LIKE ?", e.Id, "%/" + filename).Scan(&f.Id, &f.origin, &f.Path, &f.IdExercice, &f.Name, &f.Checksum, &f.Size)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetFiles returns a list of files coming with the challenge.
|
||||
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 {
|
||||
|
@ -262,6 +271,35 @@ func (f EFile) GetOrigin() string {
|
|||
return f.origin
|
||||
}
|
||||
|
||||
// AddDepend insert a new dependency to a given flag.
|
||||
func (f EFile) AddDepend(k Key) (err error) {
|
||||
_, err = DBExec("INSERT INTO exercice_files_deps (id_file, id_key) VALUES (?, ?)", f.Id, k.Id)
|
||||
return
|
||||
}
|
||||
|
||||
// GetDepends retrieve the flag's dependency list.
|
||||
func (f EFile) GetDepends() ([]Key, error) {
|
||||
if rows, err := DBQuery("SELECT id_key FROM exercice_files_deps WHERE id_file = ?", f.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
var deps = make([]Key, 0)
|
||||
for rows.Next() {
|
||||
var d int64
|
||||
if err := rows.Scan(&d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
deps = append(deps, Key{d, f.IdExercice, "", []byte{}})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
}
|
||||
}
|
||||
|
||||
// CheckFileOnDisk recalculates the hash of the file on disk.
|
||||
func (f EFile) CheckFileOnDisk() error {
|
||||
if _, size, err := checkFileHash(path.Join(FilesDir, f.Path), f.Checksum); err != nil {
|
||||
|
|
Reference in a new issue