2023-03-11 14:13:35 +05:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
// FileHistory содержит историю изменения файла
|
2023-04-03 19:43:16 +05:00
|
|
|
|
type FileHistory []FileInfo
|
2023-03-11 14:13:35 +05:00
|
|
|
|
|
|
|
|
|
// Latest возвращает информацию о последней версии файла
|
2023-04-03 19:43:16 +05:00
|
|
|
|
func (fileHistory FileHistory) Latest() FileInfo {
|
2023-03-11 14:13:35 +05:00
|
|
|
|
file := fileHistory[0]
|
|
|
|
|
|
|
|
|
|
for i := 1; i < len(fileHistory); i++ {
|
2023-04-03 19:43:16 +05:00
|
|
|
|
if fileHistory[i].ModificationTime.After(file.ModificationTime) {
|
2023-03-11 14:13:35 +05:00
|
|
|
|
file = fileHistory[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return file
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fileHistory FileHistory) Len() int {
|
|
|
|
|
return len(fileHistory)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fileHistory FileHistory) Swap(i, j int) {
|
|
|
|
|
fileHistory[i], fileHistory[j] = fileHistory[j], fileHistory[i]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fileHistory FileHistory) Less(i, j int) bool {
|
2023-04-03 19:43:16 +05:00
|
|
|
|
return fileHistory[i].ModificationTime.Before(fileHistory[j].ModificationTime)
|
2023-03-11 14:13:35 +05:00
|
|
|
|
}
|