fix cache
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
797f9d11e7
commit
fed9122523
16
main.go
16
main.go
@ -248,26 +248,26 @@ func (s *Conn) cmdServerList(args string) {
|
||||
opts.Prefix += "/"
|
||||
}
|
||||
}
|
||||
objs, err := s.loadObjects(cnt, opts)
|
||||
if err != nil {
|
||||
objs, err = s.sw.ObjectsAll(cnt, opts)
|
||||
// objs, err := s.loadObjects(cnt, opts)
|
||||
// if err != nil {
|
||||
objs, err := s.sw.ObjectsAll(cnt, opts)
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
return
|
||||
}
|
||||
s.saveObjects(cnt, objs, opts)
|
||||
}
|
||||
// }
|
||||
fmt.Printf("%+v\n", objs)
|
||||
files = append(files, NewDirItem(".", 4096, 0), NewDirItem("..", 4096, 0))
|
||||
var it os.FileInfo
|
||||
|
||||
for _, obj := range objs {
|
||||
if obj.SubDir != "" || strings.Index(obj.Name, "/") > 0 {
|
||||
continue
|
||||
}
|
||||
if obj.PseudoDirectory || obj.ContentType == "application/directory" {
|
||||
obj.Name = strings.TrimPrefix(obj.Name, opts.Prefix)
|
||||
if obj.PseudoDirectory || obj.ContentType == "application/directory" || obj.SubDir != "" {
|
||||
fmt.Printf("AAAAAA: %+v\n", obj)
|
||||
it = NewDirItem(obj.Name, obj.Bytes, 1)
|
||||
} else {
|
||||
fmt.Printf("BBBBBBBB: %+v\n", obj)
|
||||
it = NewFileItem(obj.Name, obj.Bytes, 1)
|
||||
}
|
||||
files = append(files, it)
|
||||
|
@ -14,7 +14,7 @@ var schema []string = []string{
|
||||
`CREATE TABLE IF NOT EXISTS containers (ID int, Name string, Bytes int, Count int)`,
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS containersID ON containers (ID)`,
|
||||
`CREATE INDEX IF NOT EXISTS containersName ON containers (Name)`,
|
||||
`CREATE TABLE IF NOT EXISTS objects (ID int, Container string, Prefix string, ContentType string, LastModified time, Name string, Bytes int, Count int)`,
|
||||
`CREATE TABLE IF NOT EXISTS objects (ID int, Container string, Prefix string, ContentType string, LastModified time, Name string, Bytes int, Count int, SubDir string, PseudoDir bool)`,
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS objectsID ON objects (ID)`,
|
||||
`CREATE INDEX IF NOT EXISTS objectsName ON objects (Name)`,
|
||||
`CREATE INDEX IF NOT EXISTS objectsContainer ON objects (Container)`,
|
||||
@ -102,7 +102,7 @@ func (c *Conn) saveObjects(cnt string, objs []swift.Object, opts *swift.ObjectsO
|
||||
}
|
||||
|
||||
for _, obj := range objs {
|
||||
if _, err = tx.Exec(`INSERT INTO objects (Container, Prefix, ContentType, LastModified, Name, Bytes, Count) VALUES ($1, $2, $3, $4, $5, $6, $7)`, cnt, opts.Prefix, obj.ContentType, obj.LastModified, obj.Name, obj.Bytes, 1); err != nil {
|
||||
if _, err = tx.Exec(`INSERT INTO objects (Container, Prefix, ContentType, LastModified, Name, Bytes, Count, PseudoDir, SubDir) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, cnt, opts.Prefix, obj.ContentType, obj.LastModified, obj.Name, obj.Bytes, 1, obj.PseudoDirectory, obj.SubDir); err != nil {
|
||||
fmt.Printf("aaaa %s\n", err.Error())
|
||||
return err
|
||||
}
|
||||
@ -119,7 +119,7 @@ func (c *Conn) loadObjects(cnt string, opts *swift.ObjectsOpts) ([]swift.Object,
|
||||
var objs []swift.Object
|
||||
var res swift.Object
|
||||
|
||||
result, err := c.db.Query(`SELECT ContentType, LastModified, Name, Bytes from objects where Container==$1 && Prefix==$1`, cnt, opts.Prefix)
|
||||
result, err := c.db.Query(`SELECT ContentType, LastModified, Name, Bytes, PseudoDir, SubDir from objects where Container==$1 && Prefix==$2`, cnt, opts.Prefix)
|
||||
if err != nil {
|
||||
fmt.Printf("bbb %s\n", err.Error())
|
||||
return objs, err
|
||||
@ -127,7 +127,7 @@ func (c *Conn) loadObjects(cnt string, opts *swift.ObjectsOpts) ([]swift.Object,
|
||||
defer result.Close()
|
||||
|
||||
for result.Next() {
|
||||
if err = result.Scan(&res.ContentType, &res.LastModified, &res.Name, &res.Bytes); err != nil {
|
||||
if err = result.Scan(&res.ContentType, &res.LastModified, &res.Name, &res.Bytes, &res.PseudoDirectory, &res.SubDir); err != nil {
|
||||
fmt.Printf("%s\n", err.Error())
|
||||
return objs, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user