mirror of https://github.com/perkeep/perkeep.git
Modification to allow windows build and deployement
Webserver were initialized with "tcp" and ":3179" by default and listenURL assumed that it would be treated as IPv6 and replaced [::] by localhost. Host that were listening on IPv4 0.0.0.0 didn't get the modification. Receive in localdisk were using link that failed on windows plateforms. Camlistored didn't use Json Marshaling which caused problem with the way Windows stores its paths. Change-Id: I9f62f7d46399c3514707383efcb2752dbaf1f420
This commit is contained in:
parent
3098e54163
commit
5a7510c384
|
@ -107,8 +107,8 @@ func (ds *DiskStorage) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (
|
|||
if err == nil && !pfi.IsDir() {
|
||||
log.Printf("Skipped dup on partition %q", pname)
|
||||
} else {
|
||||
if err = os.Link(fileName, partitionFileName); err != nil && !linkAlreadyExists(err) {
|
||||
log.Fatalf("got link error %T %#v", err, err)
|
||||
if err = linkOrCopy(fileName, partitionFileName); err != nil && !linkAlreadyExists(err) {
|
||||
log.Fatalf("got link or copy error %T %#v", err, err)
|
||||
return blobref.SizedBlobRef{}, err
|
||||
}
|
||||
log.Printf("Mirrored blob %s to partition %q", blobRef, pname)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// +build !windows
|
||||
|
||||
/*
|
||||
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 localdisk
|
||||
|
||||
import "os"
|
||||
|
||||
func linkOrCopy(src, dst string) error {
|
||||
return os.Link(src, dst)
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
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 localdisk
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func linkOrCopy(src, dst string) error {
|
||||
srcFile, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
dstFile, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dstFile.Close()
|
||||
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
return err
|
||||
}
|
|
@ -62,8 +62,12 @@ func (s *Server) ListenURL() string {
|
|||
scheme = "https"
|
||||
}
|
||||
if s.listener != nil {
|
||||
addr := strings.Replace(s.listener.Addr().String(), "[::]", "localhost", 1)
|
||||
return scheme + "://" + addr
|
||||
if taddr, ok := s.listener.Addr().(*net.TCPAddr); ok {
|
||||
if taddr.IP.IsUnspecified() {
|
||||
return fmt.Sprintf("%s://localhost:%d", scheme, taddr.Port)
|
||||
}
|
||||
return fmt.Sprintf("%s://%s", scheme, s.listener.Addr())
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
@ -191,27 +192,33 @@ func generateNewSecRing(filename string) (keyId string, err error) {
|
|||
return ent.PrimaryKey.KeyIdShortString(), nil
|
||||
}
|
||||
|
||||
func newDefaultConfigFile(path string) error {
|
||||
conf :=
|
||||
`{
|
||||
"listen": ":3179",
|
||||
"https": false,
|
||||
"auth": "userpass:camlistore:pass3179:+localhost",
|
||||
"identity": "%KEYID%",
|
||||
"identitySecretRing": "%SECRING%",
|
||||
"blobPath": "%BLOBPATH%",
|
||||
"mysql": "",
|
||||
"mongo": "",
|
||||
"s3": "",
|
||||
"replicateTo": [],
|
||||
"publish": {}
|
||||
type defaultConfigFile struct {
|
||||
Listen string `json:"listen"`
|
||||
HTTPS bool `json:"https"`
|
||||
Auth string `json:"auth"`
|
||||
Identity string `json:"identity"`
|
||||
IdentitySecretRing string `json:"identitySecretRing"`
|
||||
BlobPath string `json:"blobPath"`
|
||||
MySQL string `json:"mysql"`
|
||||
Mongo string `json:"mongo"`
|
||||
S3 string `json:"s3"`
|
||||
ReplicateTo []interface{} `json:"replicateTo"`
|
||||
Publish struct{} `json:"publish"`
|
||||
}
|
||||
`
|
||||
|
||||
func newDefaultConfigFile(path string) error {
|
||||
conf := defaultConfigFile{
|
||||
Listen: ":3179",
|
||||
HTTPS: false,
|
||||
Auth: "userpass:camlistore:pass3179:+localhost",
|
||||
ReplicateTo: make([]interface{}, 0),
|
||||
}
|
||||
|
||||
blobDir := osutil.CamliBlobRoot()
|
||||
if err := os.MkdirAll(blobDir, 0700); err != nil {
|
||||
return fmt.Errorf("Could not create default blobs directory: %v", err)
|
||||
}
|
||||
conf = strings.Replace(conf, "%BLOBPATH%", blobDir, 1)
|
||||
conf.BlobPath = blobDir
|
||||
|
||||
var keyId string
|
||||
secRing := osutil.IdentitySecretRing()
|
||||
|
@ -227,10 +234,15 @@ func newDefaultConfigFile(path string) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("Secret ring: %v", err)
|
||||
}
|
||||
conf.Identity = keyId
|
||||
conf.IdentitySecretRing = secRing
|
||||
|
||||
conf = strings.Replace(conf, "%SECRING%", secRing, 1)
|
||||
conf = strings.Replace(conf, "%KEYID%", keyId, 1)
|
||||
if err := ioutil.WriteFile(path, []byte(conf), 0600); err != nil {
|
||||
confData, err := json.MarshalIndent(conf, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not json encode config file : %v", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(path, confData, 0600); err != nil {
|
||||
return fmt.Errorf("Could not create or write default server config: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue