2011-05-29 17:50:17 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
2011-06-06 15:54:31 +00:00
|
|
|
"bufio"
|
2011-05-29 17:50:17 +00:00
|
|
|
"bytes"
|
|
|
|
"crypto"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2011-05-30 01:22:56 +00:00
|
|
|
"log"
|
2011-05-29 17:50:17 +00:00
|
|
|
"strings"
|
|
|
|
|
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"
|
|
|
|
"camlistore.org/pkg/blobserver"
|
|
|
|
"camlistore.org/pkg/rollsum"
|
2011-05-29 17:50:17 +00:00
|
|
|
)
|
|
|
|
|
2011-10-31 00:17:34 +00:00
|
|
|
const MaxBlobSize = 1000000
|
|
|
|
|
2011-05-30 01:22:56 +00:00
|
|
|
var _ = log.Printf
|
|
|
|
|
2011-05-29 17:50:17 +00:00
|
|
|
// WriteFileFromReader creates and uploads a "file" JSON schema
|
|
|
|
// composed of chunks of r, also uploading the chunks. The returned
|
|
|
|
// BlobRef is of the JSON file schema blob.
|
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 WriteFileFromReader(bs blobserver.StatReceiver, filename string, r io.Reader) (*blobref.BlobRef, error) {
|
2011-09-28 18:07:07 +00:00
|
|
|
m := NewFileMap(filename)
|
|
|
|
return WriteFileMap(bs, m, r)
|
|
|
|
}
|
2011-05-29 17:50:17 +00:00
|
|
|
|
2011-09-28 18:07:07 +00:00
|
|
|
// This is the simple 1MB chunk version. The rolling checksum version is below.
|
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 WriteFileMap(bs blobserver.StatReceiver, fileMap map[string]interface{}, r io.Reader) (*blobref.BlobRef, error) {
|
2011-09-08 00:51:29 +00:00
|
|
|
parts, size := []BytesPart{}, int64(0)
|
2011-05-29 17:50:17 +00:00
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
for {
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
n, err := io.Copy(buf, io.LimitReader(r, 1<<20))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if n == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
hash := crypto.SHA1.New()
|
|
|
|
io.Copy(hash, bytes.NewBuffer(buf.Bytes()))
|
|
|
|
br := blobref.FromHash("sha1", hash)
|
|
|
|
hasBlob, err := serverHasBlob(bs, br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-05-30 01:22:56 +00:00
|
|
|
if !hasBlob {
|
|
|
|
sb, err := bs.ReceiveBlob(br, buf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if expect := (blobref.SizedBlobRef{br, n}); !expect.Equal(sb) {
|
|
|
|
return nil, fmt.Errorf("schema/filewriter: wrote %s bytes, got %s ack'd", expect, sb)
|
|
|
|
}
|
2011-05-29 17:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size += n
|
2011-09-08 00:51:29 +00:00
|
|
|
parts = append(parts, BytesPart{
|
2011-07-02 16:09:50 +00:00
|
|
|
BlobRef: br,
|
|
|
|
Size: uint64(n),
|
|
|
|
Offset: 0, // into BlobRef to read from (not of dest)
|
2011-05-29 17:50:17 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2011-09-28 18:07:07 +00:00
|
|
|
err := PopulateParts(fileMap, size, parts)
|
2011-05-29 17:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2011-09-28 18:07:07 +00:00
|
|
|
json, err := MapToCamliJson(fileMap)
|
2011-05-29 17:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-11-27 19:06:12 +00:00
|
|
|
br := blobref.SHA1FromString(json)
|
2011-05-29 17:50:17 +00:00
|
|
|
sb, err := bs.ReceiveBlob(br, strings.NewReader(json))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if expect := (blobref.SizedBlobRef{br, int64(len(json))}); !expect.Equal(sb) {
|
|
|
|
return nil, fmt.Errorf("schema/filewriter: wrote %s bytes, got %s ack'd", expect, sb)
|
|
|
|
}
|
|
|
|
|
|
|
|
return br, 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 serverHasBlob(bs blobserver.BlobStatter, br *blobref.BlobRef) (have bool, err error) {
|
2011-05-29 17:50:17 +00:00
|
|
|
ch := make(chan blobref.SizedBlobRef, 1)
|
|
|
|
go func() {
|
2011-09-29 02:37:28 +00:00
|
|
|
err = bs.StatBlobs(ch, []*blobref.BlobRef{br}, 0)
|
2011-05-29 17:50:17 +00:00
|
|
|
close(ch)
|
|
|
|
}()
|
|
|
|
for _ = range ch {
|
|
|
|
have = true
|
|
|
|
}
|
|
|
|
return
|
2011-06-06 15:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type span struct {
|
|
|
|
from, to int64
|
|
|
|
bits int
|
|
|
|
br *blobref.BlobRef
|
|
|
|
children []span
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *span) size() int64 {
|
|
|
|
size := s.to - s.from
|
|
|
|
for _, cs := range s.children {
|
|
|
|
size += cs.size()
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteFileFromReaderRolling creates and uploads a "file" JSON schema
|
|
|
|
// composed of chunks of r, also uploading the chunks. The returned
|
|
|
|
// BlobRef is of the JSON file schema blob.
|
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 WriteFileFromReaderRolling(bs blobserver.StatReceiver, filename string, r io.Reader) (outbr *blobref.BlobRef, outerr error) {
|
2011-09-28 18:07:07 +00:00
|
|
|
m := NewFileMap(filename)
|
|
|
|
return WriteFileMapRolling(bs, m, r)
|
|
|
|
}
|
|
|
|
|
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 WriteFileMapRolling(bs blobserver.StatReceiver, fileMap map[string]interface{}, r io.Reader) (outbr *blobref.BlobRef, outerr error) {
|
2011-10-31 00:17:34 +00:00
|
|
|
blobSize := 0
|
2011-06-06 15:54:31 +00:00
|
|
|
bufr := bufio.NewReader(r)
|
|
|
|
spans := []span{} // the tree of spans, cut on interesting rollsum boundaries
|
|
|
|
rs := rollsum.New()
|
|
|
|
n := int64(0)
|
|
|
|
last := n
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
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
|
|
|
uploadString := func(s string) (*blobref.BlobRef, error) {
|
2011-11-27 19:06:12 +00:00
|
|
|
br := blobref.SHA1FromString(s)
|
2011-06-06 15:54:31 +00:00
|
|
|
hasIt, err := serverHasBlob(bs, br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if hasIt {
|
|
|
|
return br, nil
|
|
|
|
}
|
|
|
|
_, err = bs.ReceiveBlob(br, strings.NewReader(s))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return br, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: keep multiple of these in-flight at a time.
|
|
|
|
uploadLastSpan := func() bool {
|
|
|
|
defer buf.Reset()
|
|
|
|
br, err := uploadString(buf.String())
|
|
|
|
if err != nil {
|
|
|
|
outerr = err
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
spans[len(spans)-1].br = br
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
c, err := bufr.ReadByte()
|
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 err == io.EOF {
|
2011-06-06 15:54:31 +00:00
|
|
|
if n != last {
|
|
|
|
spans = append(spans, span{from: last, to: n})
|
|
|
|
if !uploadLastSpan() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
buf.WriteByte(c)
|
|
|
|
|
|
|
|
n++
|
2011-10-31 00:17:34 +00:00
|
|
|
blobSize++
|
2011-06-06 15:54:31 +00:00
|
|
|
rs.Roll(c)
|
|
|
|
if !rs.OnSplit() {
|
2011-10-31 00:17:34 +00:00
|
|
|
if blobSize < MaxBlobSize {
|
|
|
|
continue
|
|
|
|
}
|
2011-06-06 15:54:31 +00:00
|
|
|
}
|
2011-10-31 00:17:34 +00:00
|
|
|
blobSize = 0
|
2011-06-06 15:54:31 +00:00
|
|
|
bits := rs.Bits()
|
|
|
|
|
|
|
|
// Take any spans from the end of the spans slice that
|
|
|
|
// have a smaller 'bits' score and make them children
|
|
|
|
// of this node.
|
|
|
|
var children []span
|
|
|
|
childrenFrom := len(spans)
|
|
|
|
for childrenFrom > 0 && spans[childrenFrom-1].bits < bits {
|
|
|
|
childrenFrom--
|
|
|
|
}
|
|
|
|
if nCopy := len(spans) - childrenFrom; nCopy > 0 {
|
|
|
|
children = make([]span, nCopy)
|
|
|
|
copy(children, spans[childrenFrom:])
|
|
|
|
spans = spans[:childrenFrom]
|
|
|
|
}
|
|
|
|
|
|
|
|
spans = append(spans, span{from: last, to: n, bits: bits, children: children})
|
|
|
|
last = n
|
|
|
|
if !uploadLastSpan() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 addBytesParts func(dst *[]BytesPart, s []span) error
|
2011-06-06 15:54:31 +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
|
|
|
uploadFile := func(isFragment bool, fileSize int64, s []span) (*blobref.BlobRef, error) {
|
2011-09-08 00:51:29 +00:00
|
|
|
parts := []BytesPart{}
|
|
|
|
err := addBytesParts(&parts, s)
|
2011-06-06 15:54:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-09-28 18:07:07 +00:00
|
|
|
m := fileMap
|
2011-09-08 00:51:29 +00:00
|
|
|
if isFragment {
|
|
|
|
m = NewBytes()
|
|
|
|
}
|
|
|
|
err = PopulateParts(m, fileSize, parts)
|
2011-06-06 15:54:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
json, err := MapToCamliJson(m)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return uploadString(json)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
addBytesParts = func(dst *[]BytesPart, spansl []span) error {
|
2011-06-06 15:54:31 +00:00
|
|
|
for _, sp := range spansl {
|
|
|
|
if len(sp.children) > 0 {
|
|
|
|
childrenSize := int64(0)
|
|
|
|
for _, cs := range sp.children {
|
|
|
|
childrenSize += cs.size()
|
|
|
|
}
|
2011-09-28 18:07:07 +00:00
|
|
|
br, err := uploadFile(true, childrenSize, sp.children)
|
2011-06-06 15:54:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2011-09-08 00:51:29 +00:00
|
|
|
*dst = append(*dst, BytesPart{
|
|
|
|
BytesRef: br,
|
2011-09-27 23:02:28 +00:00
|
|
|
Size: uint64(childrenSize),
|
2011-06-06 15:54:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
if sp.from != sp.to {
|
2011-09-08 00:51:29 +00:00
|
|
|
*dst = append(*dst, BytesPart{
|
2011-07-02 16:09:50 +00:00
|
|
|
BlobRef: sp.br,
|
|
|
|
Size: uint64(sp.to - sp.from),
|
2011-06-06 15:54:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2011-05-29 17:50:17 +00:00
|
|
|
|
2011-06-06 15:54:31 +00:00
|
|
|
// The top-level content parts
|
2011-09-28 18:07:07 +00:00
|
|
|
return uploadFile(false, n, spans)
|
2011-05-29 17:50:17 +00:00
|
|
|
}
|