simplify file object
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package sqan
|
package sqan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,26 +11,6 @@ type File struct {
|
|||||||
RelativePath string `json:"relativePath,omitempty"`
|
RelativePath string `json:"relativePath,omitempty"`
|
||||||
Filename string `json:"filename,omitempty"`
|
Filename string `json:"filename,omitempty"`
|
||||||
Extension string `json:"extension,omitempty"`
|
Extension string `json:"extension,omitempty"`
|
||||||
Hash string `json:"hash,omitempty"`
|
|
||||||
Size int64 `json:"size,omitempty"`
|
Size int64 `json:"size,omitempty"`
|
||||||
Modified time.Time `json:"modified,omitempty"`
|
Modified time.Time `json:"modified,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) Process() error {
|
|
||||||
return errors.New("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFile(rootDir, absPath string) *File {
|
|
||||||
relPath, relDir, filename, extension := ParsePath(rootDir, absPath)
|
|
||||||
|
|
||||||
f := &File{
|
|
||||||
RootDir: rootDir,
|
|
||||||
AbsolutePath: absPath,
|
|
||||||
RelativeDir: relDir,
|
|
||||||
RelativePath: relPath,
|
|
||||||
Filename: filename,
|
|
||||||
Extension: extension,
|
|
||||||
}
|
|
||||||
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|||||||
+13
-4
@@ -75,8 +75,8 @@ func (s *Scanner) scan(rootDir, dir string, yield func(*File) bool) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
f := NewFile(rootDir, absPath)
|
relPath, relDir, filename, extension := ParsePath(rootDir, absPath)
|
||||||
if len(s.extensions) > 0 && !slices.Contains(s.extensions, f.Extension) {
|
if len(s.extensions) > 0 && !slices.Contains(s.extensions, extension) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +86,17 @@ func (s *Scanner) scan(rootDir, dir string, yield func(*File) bool) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Size = info.Size()
|
f := &File{
|
||||||
f.Modified = info.ModTime()
|
RootDir: rootDir,
|
||||||
|
AbsolutePath: absPath,
|
||||||
|
RelativeDir: relDir,
|
||||||
|
RelativePath: relPath,
|
||||||
|
Filename: filename,
|
||||||
|
Extension: extension,
|
||||||
|
Size: info.Size(),
|
||||||
|
Modified: info.ModTime(),
|
||||||
|
}
|
||||||
|
|
||||||
if !yield(f) {
|
if !yield(f) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user