From fffb14bc87f930cfdc14ab6fba01218606463f34 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 May 2018 02:01:50 -0700 Subject: better support FUSE Lookup() --- weed/filer/postgres_store/postgres_native.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'weed/filer/postgres_store/postgres_native.go') diff --git a/weed/filer/postgres_store/postgres_native.go b/weed/filer/postgres_store/postgres_native.go index 12b5015cf..61bd4210c 100644 --- a/weed/filer/postgres_store/postgres_native.go +++ b/weed/filer/postgres_store/postgres_native.go @@ -14,6 +14,8 @@ import ( "strings" ) +type DirectoryId int32 + func databaseExists(db *sql.DB, databaseName string) (bool, error) { sqlStatement := "SELECT datname from pg_database WHERE datname='%s'" row := db.QueryRow(fmt.Sprintf(sqlStatement, databaseName)) @@ -293,13 +295,13 @@ func (s *PostgresStore) delete(uriPath string) error { return nil } -func (s *PostgresStore) lookupDirectory(dirPath string) (filer.DirectoryId, string, error) { +func (s *PostgresStore) lookupDirectory(dirPath string) (DirectoryId, string, error) { directoryRoot, directoryName := s.mySplitPath(dirPath) sqlStatement := fmt.Sprintf("SELECT id, directoryroot, directoryname FROM %s WHERE directoryRoot=$1 AND directoryName=$2", directoriesTableName) row := s.db.QueryRow(sqlStatement, directoryRoot, directoryName) - var id filer.DirectoryId + var id DirectoryId var dirRoot string var dirName string err := row.Scan(&id, &dirRoot, &dirName) @@ -312,7 +314,7 @@ func (s *PostgresStore) lookupDirectory(dirPath string) (filer.DirectoryId, stri return id, filepath.Join(dirRoot, dirName), err } -func (s *PostgresStore) findDirectories(dirPath string, limit int) (dirs []filer.DirectoryEntry, err error) { +func (s *PostgresStore) findDirectories(dirPath string, limit int) (dirs []filer.DirectoryName, err error) { sqlStatement := fmt.Sprintf("SELECT id, directoryroot, directoryname FROM %s WHERE directoryRoot=$1 AND directoryName != '' ORDER BY id LIMIT $2", directoriesTableName) rows, err := s.db.Query(sqlStatement, dirPath, limit) @@ -323,7 +325,7 @@ func (s *PostgresStore) findDirectories(dirPath string, limit int) (dirs []filer if rows != nil { defer rows.Close() for rows.Next() { - var id filer.DirectoryId + var id DirectoryId var directoryRoot string var directoryName string @@ -331,7 +333,7 @@ func (s *PostgresStore) findDirectories(dirPath string, limit int) (dirs []filer if scanErr != nil { err = scanErr } - dirs = append(dirs, filer.DirectoryEntry{Name: (directoryName), Id: id}) + dirs = append(dirs, filer.DirectoryName(directoryName)) } } return @@ -344,7 +346,7 @@ func (s *PostgresStore) safeToDeleteDirectory(dirPath string, recursive bool) bo sqlStatement := fmt.Sprintf("SELECT id FROM %s WHERE directoryRoot LIKE $1 LIMIT 1", directoriesTableName) row := s.db.QueryRow(sqlStatement, dirPath+"%") - var id filer.DirectoryId + var id DirectoryId err := row.Scan(&id) if err != nil { if err == sql.ErrNoRows { -- cgit v1.2.3