|
@ -2,7 +2,6 @@ package Database |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"database/sql" |
|
|
"database/sql" |
|
|
"fmt" |
|
|
|
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -29,7 +28,7 @@ func FindOrCreateFileHash(rows []FilesystemHashRow) error { |
|
|
?, |
|
|
?, |
|
|
? |
|
|
? |
|
|
),` |
|
|
),` |
|
|
values = append(values, row.Path, row.Path, row.Hash, row.UpdatedAt.String()) |
|
|
|
|
|
|
|
|
values = append(values, row.Path, row.Path, row.Hash, row.UpdatedAt.Unix()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stmtString = stmtString[0 : len(stmtString)-1] |
|
|
stmtString = stmtString[0 : len(stmtString)-1] |
|
@ -44,13 +43,14 @@ func FindOrCreateFileHash(rows []FilesystemHashRow) error { |
|
|
return e |
|
|
return e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func FindModifiedFiles(hashes []string) ([]string, error) { |
|
|
|
|
|
|
|
|
func FindModifiedFiles(hashes []string) (map[int]string, error) { |
|
|
var ( |
|
|
var ( |
|
|
stmtString string |
|
|
stmtString string |
|
|
stmt *sql.Stmt |
|
|
stmt *sql.Stmt |
|
|
values []interface{} = []interface{}{} |
|
|
values []interface{} = []interface{}{} |
|
|
result *sql.Rows |
|
|
result *sql.Rows |
|
|
dirtyFiles []string = []string{} |
|
|
|
|
|
|
|
|
dirtyFiles map[int]string = make(map[int]string) |
|
|
|
|
|
counter int = 0 |
|
|
e error |
|
|
e error |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -76,68 +76,39 @@ func FindModifiedFiles(hashes []string) ([]string, error) { |
|
|
defer result.Close() |
|
|
defer result.Close() |
|
|
for result.Next() { |
|
|
for result.Next() { |
|
|
var id string |
|
|
var id string |
|
|
var hash string |
|
|
|
|
|
e = result.Scan(&id, &hash) |
|
|
|
|
|
|
|
|
var path string |
|
|
|
|
|
e = result.Scan(&id, &path) |
|
|
if e != nil { |
|
|
if e != nil { |
|
|
return dirtyFiles, e |
|
|
return dirtyFiles, e |
|
|
} |
|
|
} |
|
|
fmt.Println(id, hash) |
|
|
|
|
|
dirtyFiles = append(dirtyFiles, hash) |
|
|
|
|
|
|
|
|
dirtyFiles[counter] = path |
|
|
|
|
|
counter++ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
e = result.Err() |
|
|
e = result.Err() |
|
|
return dirtyFiles, e |
|
|
return dirtyFiles, e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
func FindNewFiles(files []string) ([]string, error) { |
|
|
|
|
|
|
|
|
func GetMostRecentTimestamp() (time.Time, error) { |
|
|
var ( |
|
|
var ( |
|
|
stmtString string |
|
|
|
|
|
stmt *sql.Stmt |
|
|
|
|
|
values []interface{} = []interface{}{} |
|
|
|
|
|
result *sql.Rows |
|
|
|
|
|
dirtyFiles []string = []string{} |
|
|
|
|
|
e error |
|
|
|
|
|
|
|
|
stmt *sql.Stmt |
|
|
|
|
|
result *sql.Row |
|
|
|
|
|
lastUpdatedAt int64 |
|
|
|
|
|
e error |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
stmtString = `select * |
|
|
|
|
|
from ( |
|
|
|
|
|
values (4),(5),(6) |
|
|
|
|
|
) as v(id) |
|
|
|
|
|
where not exists (select * |
|
|
|
|
|
from images i |
|
|
|
|
|
where i.id = v.id);` |
|
|
|
|
|
|
|
|
|
|
|
for _, row := range hashes { |
|
|
|
|
|
stmtString += "?," |
|
|
|
|
|
values = append(values, row) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stmtString = stmtString[0:len(stmtString)-1] + ")" |
|
|
|
|
|
|
|
|
|
|
|
stmt, e = DB.Prepare(stmtString) |
|
|
|
|
|
|
|
|
stmt, e = DB.Prepare(` |
|
|
|
|
|
SELECT updated_at FROM filesystem_hash |
|
|
|
|
|
ORDER BY updated_at DESC |
|
|
|
|
|
LIMIT 1; |
|
|
|
|
|
`) |
|
|
if e != nil { |
|
|
if e != nil { |
|
|
return dirtyFiles, e |
|
|
|
|
|
|
|
|
return time.Now(), e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
result, e = stmt.Query(values...) |
|
|
|
|
|
if e != nil { |
|
|
|
|
|
return dirtyFiles, e |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
result = stmt.QueryRow() |
|
|
|
|
|
|
|
|
defer result.Close() |
|
|
|
|
|
for result.Next() { |
|
|
|
|
|
var id string |
|
|
|
|
|
var hash string |
|
|
|
|
|
e = result.Scan(&id, &hash) |
|
|
|
|
|
if e != nil { |
|
|
|
|
|
return dirtyFiles, e |
|
|
|
|
|
} |
|
|
|
|
|
fmt.Println(id, hash) |
|
|
|
|
|
dirtyFiles = append(dirtyFiles, hash) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
result.Scan(&lastUpdatedAt) |
|
|
|
|
|
|
|
|
e = result.Err() |
|
|
|
|
|
return dirtyFiles, e |
|
|
|
|
|
|
|
|
return time.Unix(lastUpdatedAt, 0), nil |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|