2011-01-28 07:07:18 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2010-12-30 18:17:47 +00:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2012-03-03 20:37:54 +00:00
|
|
|
"crypto/rand"
|
2010-12-31 06:37:46 +00:00
|
|
|
"crypto/sha1"
|
2012-03-03 20:37:54 +00:00
|
|
|
"encoding/base64"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2010-12-30 18:17:47 +00:00
|
|
|
"fmt"
|
2010-12-31 06:37:46 +00:00
|
|
|
"io"
|
2011-03-25 00:42:34 +00:00
|
|
|
"log"
|
2010-12-30 18:17:47 +00:00
|
|
|
"os"
|
2012-04-14 22:26:51 +00:00
|
|
|
"path/filepath"
|
2011-01-01 10:51:15 +00:00
|
|
|
"strconv"
|
|
|
|
"sync"
|
2010-12-31 06:37:46 +00:00
|
|
|
"time"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"unicode/utf8"
|
2011-05-26 23:41:49 +00:00
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/blobref"
|
2010-12-30 18:17:47 +00:00
|
|
|
)
|
|
|
|
|
2011-03-25 00:42:34 +00:00
|
|
|
var _ = log.Printf
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
var ErrNoCamliVersion = errors.New("schema: no camliVersion key in map")
|
|
|
|
var ErrUnimplemented = errors.New("schema: unimplemented")
|
2010-12-31 06:37:46 +00:00
|
|
|
|
|
|
|
type StatHasher interface {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
Lstat(fileName string) (os.FileInfo, error)
|
|
|
|
Hash(fileName string) (*blobref.BlobRef, error)
|
2010-12-30 18:17:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:43:30 +00:00
|
|
|
type File interface {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
Close() error
|
2011-07-17 15:50:55 +00:00
|
|
|
Skip(skipBytes uint64) uint64
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
Read(p []byte) (int, error)
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 15:50:55 +00:00
|
|
|
// Directory is a read-only interface to a "directory" schema blob.
|
2011-07-14 17:43:30 +00:00
|
|
|
type Directory interface {
|
2011-07-17 15:50:55 +00:00
|
|
|
// Readdir reads the contents of the directory associated with dr
|
|
|
|
// and returns an array of up to n DirectoryEntries structures.
|
|
|
|
// Subsequent calls on the same file will yield further
|
|
|
|
// DirectoryEntries.
|
|
|
|
// If n > 0, Readdir returns at most n DirectoryEntry structures. In
|
|
|
|
// this case, if Readdir returns an empty slice, it will return
|
|
|
|
// a non-nil error explaining why. At the end of a directory,
|
|
|
|
// the error is os.EOF.
|
|
|
|
// If n <= 0, Readdir returns all the DirectoryEntries from the
|
|
|
|
// directory in a single slice. In this case, if Readdir succeeds
|
|
|
|
// (reads all the way to the end of the directory), it returns the
|
|
|
|
// slice and a nil os.Error. If it encounters an error before the
|
|
|
|
// end of the directory, Readdir returns the DirectoryEntry read
|
|
|
|
// until that point and a non-nil error.
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
Readdir(count int) ([]DirectoryEntry, error)
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Symlink interface {
|
|
|
|
// .. TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
// DirectoryEntry is a read-only interface to an entry in a (static)
|
|
|
|
// directory.
|
|
|
|
type DirectoryEntry interface {
|
|
|
|
// CamliType returns the schema blob's "camliType" field.
|
|
|
|
// This may be "file", "directory", "symlink", or other more
|
|
|
|
// obscure types added in the future.
|
|
|
|
CamliType() string
|
|
|
|
|
|
|
|
FileName() string
|
|
|
|
BlobRef() *blobref.BlobRef
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
File() (File, error) // if camliType is "file"
|
|
|
|
Directory() (Directory, error) // if camliType is "directory"
|
|
|
|
Symlink() (Symlink, error) // if camliType is "symlink"
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dirEntry is the default implementation of DirectoryEntry
|
|
|
|
type dirEntry struct {
|
2011-07-17 15:50:55 +00:00
|
|
|
ss Superset
|
|
|
|
fetcher blobref.SeekFetcher
|
|
|
|
fr *FileReader // or nil if not a file
|
|
|
|
dr *DirReader // or nil if not a directory
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (de *dirEntry) CamliType() string {
|
|
|
|
return de.ss.Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (de *dirEntry) FileName() string {
|
|
|
|
return de.ss.FileNameString()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (de *dirEntry) BlobRef() *blobref.BlobRef {
|
|
|
|
return de.ss.BlobRef
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (de *dirEntry) File() (File, error) {
|
2011-07-19 02:06:56 +00:00
|
|
|
if de.fr == nil {
|
2011-07-17 15:50:55 +00:00
|
|
|
if de.ss.Type != "file" {
|
2011-07-19 02:06:56 +00:00
|
|
|
return nil, fmt.Errorf("DirectoryEntry is camliType %q, not %q", de.ss.Type, "file")
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
fr, err := NewFileReader(de.fetcher, de.ss.BlobRef)
|
2011-07-17 15:50:55 +00:00
|
|
|
if err != nil {
|
2011-07-19 02:06:56 +00:00
|
|
|
return nil, err
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
de.fr = fr
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
return de.fr, nil
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (de *dirEntry) Directory() (Directory, error) {
|
2011-07-19 02:06:56 +00:00
|
|
|
if de.dr == nil {
|
2011-07-17 15:50:55 +00:00
|
|
|
if de.ss.Type != "directory" {
|
2011-07-19 02:06:56 +00:00
|
|
|
return nil, fmt.Errorf("DirectoryEntry is camliType %q, not %q", de.ss.Type, "directory")
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
dr, err := NewDirReader(de.fetcher, de.ss.BlobRef)
|
2011-07-17 15:50:55 +00:00
|
|
|
if err != nil {
|
2011-07-19 02:06:56 +00:00
|
|
|
return nil, err
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
de.dr = dr
|
2011-07-17 15:50:55 +00:00
|
|
|
}
|
2011-07-19 02:06:56 +00:00
|
|
|
return de.dr, nil
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (de *dirEntry) Symlink() (Symlink, error) {
|
|
|
|
return 0, errors.New("TODO: Symlink not implemented")
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewDirectoryEntry takes a Superset and returns a DirectoryEntry if
|
|
|
|
// the Supserset is valid and represents an entry in a directory. It
|
|
|
|
// must by of type "file", "directory", or "symlink".
|
2011-07-17 15:50:55 +00:00
|
|
|
// TODO(mpl): symlink
|
2011-07-14 17:43:30 +00:00
|
|
|
// TODO: "fifo", "socket", "char", "block", probably. later.
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func NewDirectoryEntry(fetcher blobref.SeekFetcher, ss *Superset) (DirectoryEntry, error) {
|
2011-07-14 17:43:30 +00:00
|
|
|
if ss == nil {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return nil, errors.New("ss was nil")
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
if ss.BlobRef == nil {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return nil, errors.New("ss.BlobRef was nil")
|
2011-07-14 17:43:30 +00:00
|
|
|
}
|
|
|
|
switch ss.Type {
|
|
|
|
case "file", "directory", "symlink":
|
|
|
|
// Okay
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("invalid DirectoryEntry camliType of %q", ss.Type)
|
|
|
|
}
|
2011-07-17 15:50:55 +00:00
|
|
|
de := &dirEntry{ss: *ss, fetcher: fetcher} // defensive copy
|
2011-07-14 17:43:30 +00:00
|
|
|
return de, nil
|
|
|
|
}
|
|
|
|
|
2011-07-17 15:50:55 +00:00
|
|
|
// NewDirectoryEntryFromBlobRef takes a BlobRef and returns a
|
|
|
|
// DirectoryEntry if the BlobRef contains a type "file", "directory"
|
|
|
|
// or "symlink".
|
|
|
|
// TODO: "fifo", "socket", "char", "block", probably. later.
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func NewDirectoryEntryFromBlobRef(fetcher blobref.SeekFetcher, blobRef *blobref.BlobRef) (DirectoryEntry, error) {
|
2011-07-17 15:50:55 +00:00
|
|
|
ss := new(Superset)
|
|
|
|
err := ss.setFromBlobRef(fetcher, blobRef)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("schema/filereader: can't fill Superset: %v\n", err)
|
|
|
|
}
|
|
|
|
return NewDirectoryEntry(fetcher, ss)
|
|
|
|
}
|
|
|
|
|
2011-03-13 18:38:53 +00:00
|
|
|
// Superset represents the superset of common camlistore JSON schema
|
|
|
|
// keys as a convenient json.Unmarshal target
|
|
|
|
type Superset struct {
|
2011-05-26 23:41:49 +00:00
|
|
|
BlobRef *blobref.BlobRef // Not in JSON, but included for
|
|
|
|
// those who want to set it.
|
2011-03-24 05:04:50 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
Version int `json:"camliVersion"`
|
|
|
|
Type string `json:"camliType"`
|
2011-03-13 18:38:53 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
Signer string `json:"camliSigner"`
|
|
|
|
Sig string `json:"camliSig"`
|
2011-03-13 18:38:53 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
ClaimType string `json:"claimType"`
|
|
|
|
ClaimDate string `json:"claimDate"`
|
2011-03-13 18:38:53 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
Permanode string `json:"permaNode"`
|
|
|
|
Attribute string `json:"attribute"`
|
|
|
|
Value string `json:"value"`
|
2011-03-23 05:11:27 +00:00
|
|
|
|
2011-05-29 17:39:41 +00:00
|
|
|
// TODO: ditch both the FooBytes variants below. a string doesn't have to be UTF-8.
|
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
FileName string `json:"fileName"`
|
|
|
|
FileNameBytes []interface{} `json:"fileNameBytes"` // TODO: needs custom UnmarshalJSON?
|
2011-03-26 01:36:08 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
SymlinkTarget string `json:"symlinkTarget"`
|
|
|
|
SymlinkTargetBytes []interface{} `json:"symlinkTargetBytes"` // TODO: needs custom UnmarshalJSON?
|
2011-03-26 01:36:08 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
UnixPermission string `json:"unixPermission"`
|
|
|
|
UnixOwnerId int `json:"unixOwnerId"`
|
|
|
|
UnixOwner string `json:"unixOwner"`
|
|
|
|
UnixGroupId int `json:"unixGroupId"`
|
|
|
|
UnixGroup string `json:"unixGroup"`
|
|
|
|
UnixMtime string `json:"unixMtime"`
|
|
|
|
UnixCtime string `json:"unixCtime"`
|
|
|
|
UnixAtime string `json:"unixAtime"`
|
2011-03-23 05:11:27 +00:00
|
|
|
|
2011-09-08 00:51:29 +00:00
|
|
|
Parts []*BytesPart `json:"parts"`
|
2011-03-23 05:32:11 +00:00
|
|
|
|
2011-06-30 04:36:14 +00:00
|
|
|
Entries string `json:"entries"` // for directories, a blobref to a static-set
|
|
|
|
Members []string `json:"members"` // for static sets (for directory static-sets:
|
2011-05-26 23:41:49 +00:00
|
|
|
// blobrefs to child dirs/files)
|
2011-03-23 05:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 00:51:29 +00:00
|
|
|
type BytesPart struct {
|
|
|
|
// Required.
|
|
|
|
Size uint64 `json:"size"`
|
|
|
|
|
|
|
|
// At most one of:
|
|
|
|
BlobRef *blobref.BlobRef `json:"blobRef,omitempty"`
|
|
|
|
BytesRef *blobref.BlobRef `json:"bytesRef,omitempty"`
|
|
|
|
|
|
|
|
// Optional (default value is zero if unset anyway):
|
|
|
|
Offset uint64 `json:"offset,omitempty"`
|
2011-03-24 22:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-03-26 01:36:08 +00:00
|
|
|
func stringFromMixedArray(parts []interface{}) string {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
for _, part := range parts {
|
|
|
|
if s, ok := part.(string); ok {
|
|
|
|
buf.WriteString(s)
|
|
|
|
continue
|
|
|
|
}
|
2011-03-26 01:45:10 +00:00
|
|
|
if num, ok := part.(float64); ok {
|
|
|
|
buf.WriteByte(byte(num))
|
2011-05-26 23:41:49 +00:00
|
|
|
continue
|
2011-03-26 01:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2011-09-08 00:51:29 +00:00
|
|
|
func (ss *Superset) SumPartsSize() (size uint64) {
|
|
|
|
for _, part := range ss.Parts {
|
|
|
|
size += uint64(part.Size)
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2011-03-26 01:36:08 +00:00
|
|
|
func (ss *Superset) SymlinkTargetString() string {
|
|
|
|
if ss.SymlinkTarget != "" {
|
|
|
|
return ss.SymlinkTarget
|
|
|
|
}
|
|
|
|
return stringFromMixedArray(ss.SymlinkTargetBytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *Superset) FileNameString() string {
|
|
|
|
if ss.FileName != "" {
|
|
|
|
return ss.FileName
|
|
|
|
}
|
|
|
|
return stringFromMixedArray(ss.FileNameBytes)
|
|
|
|
}
|
|
|
|
|
2011-03-23 05:11:27 +00:00
|
|
|
func (ss *Superset) HasFilename(name string) bool {
|
2011-03-26 01:36:08 +00:00
|
|
|
return ss.FileNameString() == name
|
2011-03-13 18:38:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 16:04:42 +00:00
|
|
|
func (ss *Superset) FileMode() os.FileMode {
|
|
|
|
var mode os.FileMode
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
m64, err := strconv.ParseUint(ss.UnixPermission, 8, 64)
|
2011-03-23 05:59:45 +00:00
|
|
|
if err == nil {
|
2012-03-05 16:04:42 +00:00
|
|
|
mode = mode | os.FileMode(m64)
|
2011-03-23 05:59:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 16:04:42 +00:00
|
|
|
// TODO: add other types (block, char, etc)
|
2011-03-23 05:59:45 +00:00
|
|
|
switch ss.Type {
|
|
|
|
case "directory":
|
2012-03-05 16:04:42 +00:00
|
|
|
mode = mode | os.ModeDir
|
2011-03-23 05:59:45 +00:00
|
|
|
case "file":
|
2012-03-05 16:04:42 +00:00
|
|
|
// No extra bit.
|
2011-03-23 05:59:45 +00:00
|
|
|
case "symlink":
|
2012-03-05 16:04:42 +00:00
|
|
|
mode = mode | os.ModeSymlink
|
2011-03-23 05:59:45 +00:00
|
|
|
}
|
2012-03-05 16:04:42 +00:00
|
|
|
return mode
|
2011-03-23 05:59:45 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 00:03:07 +00:00
|
|
|
// MapUid returns the most appropriate mapping from this file's owner
|
|
|
|
// to the local machine's owner, trying first a match by name,
|
|
|
|
// followed by just mapping the number through directly.
|
|
|
|
func (ss *Superset) MapUid() int {
|
|
|
|
if ss.UnixOwner != "" {
|
|
|
|
uid, ok := getUidFromName(ss.UnixOwner)
|
|
|
|
if ok {
|
|
|
|
return uid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ss.UnixOwnerId // TODO: will be 0 if unset, which isn't ideal
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *Superset) MapGid() int {
|
|
|
|
if ss.UnixGroup != "" {
|
|
|
|
gid, ok := getGidFromName(ss.UnixGroup)
|
|
|
|
if ok {
|
|
|
|
return gid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ss.UnixGroupId // TODO: will be 0 if unset, which isn't ideal
|
|
|
|
}
|
|
|
|
|
2012-04-28 08:34:53 +00:00
|
|
|
func (ss *Superset) ModTime() time.Time {
|
|
|
|
if ss.UnixMtime == "" {
|
|
|
|
return time.Time{}
|
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
t, err := time.Parse(time.RFC3339, ss.UnixMtime)
|
|
|
|
if err != nil {
|
2012-04-28 08:34:53 +00:00
|
|
|
return time.Time{}
|
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
return t
|
2012-04-28 08:34:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 06:37:46 +00:00
|
|
|
var DefaultStatHasher = &defaultStatHasher{}
|
|
|
|
|
|
|
|
type defaultStatHasher struct{}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (d *defaultStatHasher) Lstat(fileName string) (os.FileInfo, error) {
|
2010-12-31 06:37:46 +00:00
|
|
|
return os.Lstat(fileName)
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (d *defaultStatHasher) Hash(fileName string) (*blobref.BlobRef, error) {
|
2010-12-31 06:37:46 +00:00
|
|
|
s1 := sha1.New()
|
2011-04-07 17:58:29 +00:00
|
|
|
file, err := os.Open(fileName)
|
2010-12-31 06:37:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
_, err = io.Copy(s1, file)
|
2011-03-13 18:39:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2010-12-31 06:37:46 +00:00
|
|
|
return blobref.FromHash("sha1", s1), nil
|
|
|
|
}
|
2010-12-30 18:17:47 +00:00
|
|
|
|
2011-01-01 23:44:08 +00:00
|
|
|
type StaticSet struct {
|
2011-03-13 18:39:08 +00:00
|
|
|
l sync.Mutex
|
2011-01-01 23:44:08 +00:00
|
|
|
refs []*blobref.BlobRef
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSet) Add(ref *blobref.BlobRef) {
|
|
|
|
ss.l.Lock()
|
|
|
|
defer ss.l.Unlock()
|
|
|
|
ss.refs = append(ss.refs, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCamliMap(version int, ctype string) map[string]interface{} {
|
|
|
|
m := make(map[string]interface{})
|
2011-03-13 18:39:08 +00:00
|
|
|
m["camliVersion"] = version
|
|
|
|
m["camliType"] = ctype
|
2011-01-01 23:44:08 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2011-01-17 05:16:54 +00:00
|
|
|
func NewUnsignedPermanode() map[string]interface{} {
|
2011-01-16 02:10:58 +00:00
|
|
|
m := newCamliMap(1, "permanode")
|
|
|
|
chars := make([]byte, 20)
|
2012-03-03 20:37:54 +00:00
|
|
|
_, err := io.ReadFull(rand.Reader, chars)
|
|
|
|
if err != nil {
|
|
|
|
panic("error reading random bytes: " + err.Error())
|
2011-01-16 02:10:58 +00:00
|
|
|
}
|
2012-03-03 20:37:54 +00:00
|
|
|
m["random"] = base64.StdEncoding.EncodeToString(chars)
|
2011-01-17 05:16:54 +00:00
|
|
|
return m
|
2011-01-16 02:10:58 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 22:41:19 +00:00
|
|
|
func NewPlannedPermanode(key string) map[string]interface{} {
|
|
|
|
m := newCamliMap(1, "permanode")
|
|
|
|
m["key"] = key
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2011-01-01 23:44:08 +00:00
|
|
|
// Map returns a Camli map of camliType "static-set"
|
|
|
|
func (ss *StaticSet) Map() map[string]interface{} {
|
|
|
|
m := newCamliMap(1, "static-set")
|
|
|
|
ss.l.Lock()
|
|
|
|
defer ss.l.Unlock()
|
|
|
|
|
|
|
|
members := make([]string, 0, len(ss.refs))
|
|
|
|
if ss.refs != nil {
|
|
|
|
for _, ref := range ss.refs {
|
|
|
|
members = append(members, ref.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m["members"] = members
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2012-04-15 14:45:10 +00:00
|
|
|
func MapToCamliJSON(m map[string]interface{}) (string, error) {
|
2010-12-30 18:17:47 +00:00
|
|
|
version, hasVersion := m["camliVersion"]
|
|
|
|
if !hasVersion {
|
2011-05-26 23:41:49 +00:00
|
|
|
return "", ErrNoCamliVersion
|
2010-12-30 18:17:47 +00:00
|
|
|
}
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
delete(m, "camliVersion")
|
2010-12-30 18:17:47 +00:00
|
|
|
jsonBytes, err := json.MarshalIndent(m, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
m["camliVersion"] = version
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
fmt.Fprintf(buf, "{\"camliVersion\": %v,\n", version)
|
|
|
|
buf.Write(jsonBytes[2:])
|
|
|
|
return string(buf.Bytes()), nil
|
|
|
|
}
|
|
|
|
|
2011-09-08 00:51:29 +00:00
|
|
|
func NewFileMap(fileName string) map[string]interface{} {
|
|
|
|
m := NewCommonFilenameMap(fileName)
|
|
|
|
m["camliType"] = "file"
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2011-05-29 17:39:41 +00:00
|
|
|
func NewCommonFilenameMap(fileName string) map[string]interface{} {
|
2012-04-14 01:40:59 +00:00
|
|
|
m := newCamliMap(1, "" /* no type yet */)
|
2011-06-06 15:54:31 +00:00
|
|
|
if fileName != "" {
|
2012-04-14 22:26:51 +00:00
|
|
|
baseName := filepath.Base(fileName)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
if utf8.ValidString(baseName) {
|
2011-06-06 15:54:31 +00:00
|
|
|
m["fileName"] = baseName
|
|
|
|
} else {
|
|
|
|
m["fileNameBytes"] = []uint8(baseName)
|
|
|
|
}
|
2010-12-31 06:37:46 +00:00
|
|
|
}
|
2011-05-29 17:39:41 +00:00
|
|
|
return m
|
|
|
|
}
|
2011-01-01 22:44:19 +00:00
|
|
|
|
2012-04-14 01:40:59 +00:00
|
|
|
var populateSchemaStat []func(schemaMap map[string]interface{}, fi os.FileInfo)
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func NewCommonFileMap(fileName string, fi os.FileInfo) map[string]interface{} {
|
2011-05-29 17:39:41 +00:00
|
|
|
m := NewCommonFilenameMap(fileName)
|
2011-01-01 22:44:19 +00:00
|
|
|
// Common elements (from file-common.txt)
|
2012-04-28 08:34:53 +00:00
|
|
|
if fi.Mode()&os.ModeSymlink == 0 {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
m["unixPermission"] = fmt.Sprintf("0%o", fi.Mode().Perm())
|
2011-02-03 16:19:40 +00:00
|
|
|
}
|
2012-04-14 01:40:59 +00:00
|
|
|
|
|
|
|
// OS-specific population; defined in schema_posix.go, etc. (not on App Engine)
|
|
|
|
for _, f := range populateSchemaStat {
|
|
|
|
f(m, fi)
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
if mtime := fi.ModTime(); !mtime.IsZero() {
|
|
|
|
m["unixMtime"] = RFC3339FromTime(mtime)
|
2012-04-14 01:40:59 +00:00
|
|
|
}
|
2010-12-31 06:37:46 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func PopulateParts(m map[string]interface{}, size int64, parts []BytesPart) error {
|
2011-09-08 00:51:29 +00:00
|
|
|
sumSize := int64(0)
|
2011-01-01 22:44:19 +00:00
|
|
|
mparts := make([]map[string]interface{}, len(parts))
|
|
|
|
for idx, part := range parts {
|
|
|
|
mpart := make(map[string]interface{})
|
|
|
|
mparts[idx] = mpart
|
2011-09-08 00:51:29 +00:00
|
|
|
switch {
|
|
|
|
case part.BlobRef != nil && part.BytesRef != nil:
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return errors.New("schema: part contains both blobRef and bytesRef")
|
2011-09-08 00:51:29 +00:00
|
|
|
case part.BlobRef != nil:
|
2011-06-06 15:54:31 +00:00
|
|
|
mpart["blobRef"] = part.BlobRef.String()
|
2011-09-08 00:51:29 +00:00
|
|
|
case part.BytesRef != nil:
|
|
|
|
mpart["bytesRef"] = part.BytesRef.String()
|
2011-06-06 15:54:31 +00:00
|
|
|
}
|
2011-01-01 22:44:19 +00:00
|
|
|
mpart["size"] = part.Size
|
2011-09-08 00:51:29 +00:00
|
|
|
sumSize += int64(part.Size)
|
2011-01-01 22:44:19 +00:00
|
|
|
if part.Offset != 0 {
|
|
|
|
mpart["offset"] = part.Offset
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 00:51:29 +00:00
|
|
|
if sumSize != size {
|
|
|
|
return fmt.Errorf("schema: declared size %d doesn't match sum of parts size %d", size, sumSize)
|
2010-12-30 18:17:47 +00:00
|
|
|
}
|
2011-09-08 00:51:29 +00:00
|
|
|
m["parts"] = mparts
|
2011-01-01 21:12:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func PopulateSymlinkMap(m map[string]interface{}, fileName string) error {
|
2011-01-01 21:12:45 +00:00
|
|
|
m["camliType"] = "symlink"
|
|
|
|
target, err := os.Readlink(fileName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
if utf8.ValidString(target) {
|
2011-01-01 21:12:45 +00:00
|
|
|
m["symlinkTarget"] = target
|
|
|
|
} else {
|
|
|
|
m["symlinkTargetBytes"] = []uint8(target)
|
|
|
|
}
|
2010-12-31 06:37:46 +00:00
|
|
|
return nil
|
2010-12-30 18:17:47 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 00:51:29 +00:00
|
|
|
func NewBytes() map[string]interface{} {
|
|
|
|
return newCamliMap(1, "bytes")
|
|
|
|
}
|
|
|
|
|
2011-01-01 23:44:08 +00:00
|
|
|
func PopulateDirectoryMap(m map[string]interface{}, staticSetRef *blobref.BlobRef) {
|
|
|
|
m["camliType"] = "directory"
|
|
|
|
m["entries"] = staticSetRef.String()
|
|
|
|
}
|
|
|
|
|
2011-01-26 06:44:03 +00:00
|
|
|
func NewShareRef(authType string, target *blobref.BlobRef, transitive bool) map[string]interface{} {
|
2011-03-13 03:28:18 +00:00
|
|
|
m := newCamliMap(1, "share")
|
2011-01-26 06:44:03 +00:00
|
|
|
m["authType"] = authType
|
|
|
|
m["target"] = target.String()
|
|
|
|
m["transitive"] = transitive
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2011-03-13 03:28:18 +00:00
|
|
|
func NewClaim(permaNode *blobref.BlobRef, claimType string) map[string]interface{} {
|
|
|
|
m := newCamliMap(1, "claim")
|
|
|
|
m["permaNode"] = permaNode.String()
|
|
|
|
m["claimType"] = claimType
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
m["claimDate"] = RFC3339FromTime(time.Now())
|
2011-03-13 03:28:18 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAttrChangeClaim(permaNode *blobref.BlobRef, claimType, attr, value string) map[string]interface{} {
|
2011-03-14 05:21:58 +00:00
|
|
|
m := NewClaim(permaNode, claimType)
|
2011-03-13 03:28:18 +00:00
|
|
|
m["attribute"] = attr
|
|
|
|
m["value"] = value
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSetAttributeClaim(permaNode *blobref.BlobRef, attr, value string) map[string]interface{} {
|
|
|
|
return newAttrChangeClaim(permaNode, "set-attribute", attr, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAddAttributeClaim(permaNode *blobref.BlobRef, attr, value string) map[string]interface{} {
|
|
|
|
return newAttrChangeClaim(permaNode, "add-attribute", attr, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDelAttributeClaim(permaNode *blobref.BlobRef, attr string) map[string]interface{} {
|
|
|
|
m := newAttrChangeClaim(permaNode, "del-attribute", attr, "")
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
delete(m, "value")
|
2011-03-13 03:28:18 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2011-01-26 06:44:03 +00:00
|
|
|
// Types of ShareRefs
|
|
|
|
const ShareHaveRef = "haveref"
|
|
|
|
|
2012-05-13 20:27:11 +00:00
|
|
|
// RFC3339FromTime returns an RFC3339-formatted time in UTC.
|
|
|
|
// Fractional seconds are only included if the time has fractional
|
|
|
|
// seconds.
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func RFC3339FromTime(t time.Time) string {
|
2012-05-13 20:27:11 +00:00
|
|
|
if t.UnixNano() % 1e9 == 0 {
|
|
|
|
return t.UTC().Format(time.RFC3339)
|
2010-12-31 20:13:33 +00:00
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
return t.UTC().Format(time.RFC3339Nano)
|
2010-12-31 20:13:33 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 17:29:16 +00:00
|
|
|
func NanosFromRFC3339(timestr string) int64 {
|
2012-05-13 20:27:11 +00:00
|
|
|
t, err := time.Parse(time.RFC3339, timestr)
|
2011-03-29 17:29:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return -1
|
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
return t.UnixNano()
|
2011-03-29 17:29:16 +00:00
|
|
|
}
|