large performance improvement
sorting 400k - 800k files is much faster, and no longer unbearable
This commit is contained in:
parent
73da0a88fe
commit
20f6dc92bc
|
@ -8,17 +8,17 @@ import (
|
||||||
|
|
||||||
const sep = string(os.PathSeparator)
|
const sep = string(os.PathSeparator)
|
||||||
|
|
||||||
|
var (
|
||||||
|
home string = os.Getenv("HOME")
|
||||||
|
pwd, _ = os.Getwd()
|
||||||
|
)
|
||||||
|
|
||||||
// UnExpand unexpands some directory shortcuts
|
// UnExpand unexpands some directory shortcuts
|
||||||
//
|
//
|
||||||
// $HOME -> ~
|
// $HOME -> ~
|
||||||
// $PWD -> .
|
// $PWD -> .
|
||||||
// workdir -> /
|
// workdir -> /
|
||||||
func UnExpand(dir, workdir string) (outdir string) {
|
func UnExpand(dir, workdir string) (outdir string) {
|
||||||
var (
|
|
||||||
home string = os.Getenv("HOME")
|
|
||||||
pwd, _ = os.Getwd()
|
|
||||||
)
|
|
||||||
|
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
outdir = cleanDir(dir, pwd)
|
outdir = cleanDir(dir, pwd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -22,7 +21,7 @@ type DiskFile struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f DiskFile) Name() string { return f.name }
|
func (f DiskFile) Name() string { return f.name }
|
||||||
func (f DiskFile) Path() string { return filepath.Join(f.path, f.name) }
|
func (f DiskFile) Path() string { return f.path }
|
||||||
func (f DiskFile) Date() time.Time { return f.modified }
|
func (f DiskFile) Date() time.Time { return f.modified }
|
||||||
func (f DiskFile) IsDir() bool { return f.isdir }
|
func (f DiskFile) IsDir() bool { return f.isdir }
|
||||||
func (f DiskFile) Filesize() int64 {
|
func (f DiskFile) Filesize() int64 {
|
||||||
|
@ -33,7 +32,9 @@ func (f DiskFile) Filesize() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f DiskFile) String() string {
|
func (f DiskFile) String() string {
|
||||||
return fmt.Sprintf(string_format, f.name, f.path, f.modified.Format(time.UnixDate), f.filesize, f.isdir)
|
// this is unique enough because two files can't be named the same in the same directory
|
||||||
|
// right???
|
||||||
|
return f.name + f.path
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDisk(path string) (DiskFile, error) {
|
func NewDisk(path string) (DiskFile, error) {
|
||||||
|
@ -56,7 +57,7 @@ func NewDisk(path string) (DiskFile, error) {
|
||||||
|
|
||||||
return DiskFile{
|
return DiskFile{
|
||||||
name: name,
|
name: name,
|
||||||
path: base_path,
|
path: filepath.Join(base_path, name),
|
||||||
filesize: info.Size(),
|
filesize: info.Size(),
|
||||||
modified: info.ModTime(),
|
modified: info.ModTime(),
|
||||||
isdir: info.IsDir(),
|
isdir: info.IsDir(),
|
||||||
|
@ -132,7 +133,7 @@ func walk_dir(dir string, f *filter.Filter) (files Files) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
files = append(files, DiskFile{
|
files = append(files, DiskFile{
|
||||||
path: filepath.Dir(p),
|
path: p,
|
||||||
name: name,
|
name: name,
|
||||||
filesize: i.Size(),
|
filesize: i.Size(),
|
||||||
modified: i.ModTime(),
|
modified: i.ModTime(),
|
||||||
|
@ -173,7 +174,7 @@ func read_dir(dir string, f *filter.Filter) (files Files) {
|
||||||
log.Debugf("found matching file: %s %s", name, info.ModTime())
|
log.Debugf("found matching file: %s %s", name, info.ModTime())
|
||||||
files = append(files, DiskFile{
|
files = append(files, DiskFile{
|
||||||
name: name,
|
name: name,
|
||||||
path: path,
|
path: filepath.Join(path, name),
|
||||||
modified: info.ModTime(),
|
modified: info.ModTime(),
|
||||||
filesize: info.Size(),
|
filesize: info.Size(),
|
||||||
isdir: info.IsDir(),
|
isdir: info.IsDir(),
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const string_format = "%s %s %s %d %t"
|
|
||||||
|
|
||||||
type File interface {
|
type File interface {
|
||||||
Name() string
|
Name() string
|
||||||
Path() string
|
Path() string
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (t TrashInfo) Filesize() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TrashInfo) String() string {
|
func (t TrashInfo) String() string {
|
||||||
return fmt.Sprintf(string_format, t.name, t.path, t.trashed.Format(time.UnixDate), t.filesize, t.isdir)
|
return t.name + t.path + t.ogpath + t.trashinfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr error) {
|
func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr error) {
|
||||||
|
|
Loading…
Reference in a new issue