all: make private functions / variables / constant which shouldn't be public

This commit is contained in:
Nick Craig-Wood 2014-07-29 17:50:07 +01:00
parent 442578ca25
commit c389616657
6 changed files with 45 additions and 52 deletions

View File

@ -38,8 +38,8 @@ const (
rcloneClientId = "202264815644.apps.googleusercontent.com"
rcloneClientSecret = "X4Z3ca8xfWDb1Voo-F9a7ZxJ"
driveFolderType = "application/vnd.google-apps.folder"
RFC3339In = time.RFC3339
RFC3339Out = "2006-01-02T15:04:05.000000000Z07:00"
timeFormatIn = time.RFC3339
timeFormatOut = "2006-01-02T15:04:05.000000000Z07:00"
)
// Globals
@ -249,7 +249,7 @@ func NewFs(name, path string) (fs.Fs, error) {
// No root so return old f
return f, nil
}
obj, err := newF.newFsObjectWithInfo(remote, nil)
obj, err := newF.newFsObjectWithInfoErr(remote, nil)
if err != nil {
// File doesn't exist so return old f
return f, nil
@ -262,7 +262,7 @@ func NewFs(name, path string) (fs.Fs, error) {
}
// Return an FsObject from a path
func (f *FsDrive) newFsObjectWithInfo(remote string, info *drive.File) (fs.Object, error) {
func (f *FsDrive) newFsObjectWithInfoErr(remote string, info *drive.File) (fs.Object, error) {
fs := &FsObjectDrive{
drive: f,
remote: remote,
@ -282,8 +282,8 @@ func (f *FsDrive) newFsObjectWithInfo(remote string, info *drive.File) (fs.Objec
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsDrive) NewFsObjectWithInfo(remote string, info *drive.File) fs.Object {
fs, _ := f.newFsObjectWithInfo(remote, info)
func (f *FsDrive) newFsObjectWithInfo(remote string, info *drive.File) fs.Object {
fs, _ := f.newFsObjectWithInfoErr(remote, info)
// Errors have already been logged
return fs
}
@ -292,7 +292,7 @@ func (f *FsDrive) NewFsObjectWithInfo(remote string, info *drive.File) fs.Object
//
// May return nil if an error occurred
func (f *FsDrive) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// Path should be directory path either "" or "path/"
@ -316,7 +316,7 @@ func (f *FsDrive) listDirRecursive(dirId string, path string, out fs.ObjectsChan
} else {
// If item has no MD5 sum it isn't stored on drive, so ignore it
if item.Md5Checksum != "" {
if fs := f.NewFsObjectWithInfo(path+item.Title, item); fs != nil {
if fs := f.newFsObjectWithInfo(path+item.Title, item); fs != nil {
out <- fs
}
}
@ -366,7 +366,7 @@ func (f *FsDrive) listDirFull(dirId string, path string, out fs.ObjectsChan) err
// fmt.Printf("file %s %s %s\n", path, item.Title, item.Id)
// If item has no MD5 sum it isn't stored on drive, so ignore it
if item.Md5Checksum != "" {
if fs := f.NewFsObjectWithInfo(path, item); fs != nil {
if fs := f.newFsObjectWithInfo(path, item); fs != nil {
out <- fs
}
}
@ -589,7 +589,7 @@ func (f *FsDrive) ListDir() fs.DirChan {
Bytes: -1,
Count: -1,
}
dir.When, _ = time.Parse(RFC3339In, item.ModifiedDate)
dir.When, _ = time.Parse(timeFormatIn, item.ModifiedDate)
out <- dir
return false
})
@ -650,7 +650,7 @@ func (f *FsDrive) Put(in io.Reader, remote string, modTime time.Time, size int64
if mimeType == "" {
mimeType = "application/octet-stream"
}
modifiedDate := modTime.Format(RFC3339Out)
modifiedDate := modTime.Format(timeFormatOut)
// Define the metadata for the file we are going to create.
info := &drive.File{
@ -808,7 +808,7 @@ func (o *FsObjectDrive) ModTime() time.Time {
fs.Log(o, "Failed to read metadata: %s", err)
return time.Now()
}
modTime, err := time.Parse(RFC3339In, o.modifiedDate)
modTime, err := time.Parse(timeFormatIn, o.modifiedDate)
if err != nil {
fs.Log(o, "Failed to read mtime from object: %s", err)
return time.Now()
@ -826,7 +826,7 @@ func (o *FsObjectDrive) SetModTime(modTime time.Time) {
}
// New metadata
info := &drive.File{
ModifiedDate: modTime.Format(RFC3339Out),
ModifiedDate: modTime.Format(timeFormatOut),
}
// Set modified date
_, err = o.drive.svc.Files.Update(o.id, info).SetModifiedDate(true).Do()
@ -867,7 +867,7 @@ func (o *FsObjectDrive) Open() (in io.ReadCloser, err error) {
func (o *FsObjectDrive) Update(in io.Reader, modTime time.Time, size int64) error {
info := &drive.File{
Id: o.id,
ModifiedDate: modTime.Format(RFC3339Out),
ModifiedDate: modTime.Format(timeFormatOut),
}
// Make the API request to upload metadata and file data.

View File

@ -45,8 +45,8 @@ const (
md5sumField = "md5sum"
mtimeField = "mtime"
maxCommitRetries = 5
RFC3339In = time.RFC3339
RFC3339Out = "2006-01-02T15:04:05.000000000Z07:00"
timeFormatIn = time.RFC3339
timeFormatOut = "2006-01-02T15:04:05.000000000Z07:00"
)
// Register with Fs
@ -54,7 +54,7 @@ func init() {
fs.Register(&fs.FsInfo{
Name: "dropbox",
NewFs: NewFs,
Config: Config,
Config: configHelper,
Options: []fs.Option{{
Name: "app_key",
Help: "Dropbox App Key - leave blank to use rclone's.",
@ -66,7 +66,7 @@ func init() {
}
// Configuration helper - called after the user has put in the defaults
func Config(name string) {
func configHelper(name string) {
// See if already have a token
token := fs.ConfigFile.MustValue(name, "token")
if token != "" {
@ -214,7 +214,9 @@ func (f *FsDropbox) openDataStore() {
}
// Return an FsObject from a path
func (f *FsDropbox) newFsObjectWithInfo(remote string, info *dropbox.Entry) (fs.Object, error) {
//
// May return nil if an error occurred
func (f *FsDropbox) newFsObjectWithInfo(remote string, info *dropbox.Entry) fs.Object {
o := &FsObjectDropbox{
dropbox: f,
remote: remote,
@ -225,26 +227,17 @@ func (f *FsDropbox) newFsObjectWithInfo(remote string, info *dropbox.Entry) (fs.
err := o.readEntryAndSetMetadata()
if err != nil {
// logged already fs.Debug("Failed to read info: %s", err)
return nil, err
return nil
}
}
return o, nil
}
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsDropbox) NewFsObjectWithInfo(remote string, info *dropbox.Entry) fs.Object {
fs, _ := f.newFsObjectWithInfo(remote, info)
// Errors have already been logged
return fs
return o
}
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsDropbox) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// Strips the root off entry and returns it
@ -290,7 +283,7 @@ func (f *FsDropbox) list(out fs.ObjectsChan) {
// ignore directories
} else {
path := f.stripRoot(entry)
out <- f.NewFsObjectWithInfo(path, entry)
out <- f.newFsObjectWithInfo(path, entry)
}
}
}
@ -625,7 +618,7 @@ func (o *FsObjectDropbox) readMetaData() (err error) {
if !ok {
fs.Debug(o, "mtime not a string")
} else {
modTime, err := time.Parse(RFC3339In, mtime)
modTime, err := time.Parse(timeFormatIn, mtime)
if err != nil {
return err
}
@ -671,7 +664,7 @@ func (o *FsObjectDropbox) setModTimeAndMd5sum(modTime time.Time, md5sum string)
}
if !modTime.IsZero() {
mtime := modTime.Format(RFC3339Out)
mtime := modTime.Format(timeFormatOut)
err := record.Set(mtimeField, mtime)
if err != nil {
return fmt.Errorf("Couldn't set mtime record: %s", err)

View File

@ -34,8 +34,8 @@ import (
const (
rcloneClientId = "202264815644.apps.googleusercontent.com"
rcloneClientSecret = "X4Z3ca8xfWDb1Voo-F9a7ZxJ"
RFC3339In = time.RFC3339
RFC3339Out = "2006-01-02T15:04:05.000000000Z07:00"
timeFormatIn = time.RFC3339
timeFormatOut = "2006-01-02T15:04:05.000000000Z07:00"
metaMtime = "mtime" // key to store mtime under in metadata
listChunks = 256 // chunk size to read directory listings
)
@ -215,7 +215,7 @@ func NewFs(name, root string) (fs.Fs, error) {
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsStorage) NewFsObjectWithInfo(remote string, info *storage.Object) fs.Object {
func (f *FsStorage) newFsObjectWithInfo(remote string, info *storage.Object) fs.Object {
o := &FsObjectStorage{
storage: f,
remote: remote,
@ -236,7 +236,7 @@ func (f *FsStorage) NewFsObjectWithInfo(remote string, info *storage.Object) fs.
//
// May return nil if an error occurred
func (f *FsStorage) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// list the objects into the function supplied
@ -293,7 +293,7 @@ func (f *FsStorage) List() fs.ObjectsChan {
go func() {
defer close(out)
f.list(false, func(remote string, object *storage.Object) {
if fs := f.NewFsObjectWithInfo(remote, object); fs != nil {
if fs := f.newFsObjectWithInfo(remote, object); fs != nil {
out <- fs
}
})
@ -441,7 +441,7 @@ func (o *FsObjectStorage) setMetaData(info *storage.Object) {
// read mtime out of metadata if available
mtimeString, ok := info.Metadata[metaMtime]
if ok {
modTime, err := time.Parse(RFC3339In, mtimeString)
modTime, err := time.Parse(timeFormatIn, mtimeString)
if err == nil {
o.modTime = modTime
return
@ -451,7 +451,7 @@ func (o *FsObjectStorage) setMetaData(info *storage.Object) {
}
// Fallback to the Updated time
modTime, err := time.Parse(RFC3339In, info.Updated)
modTime, err := time.Parse(timeFormatIn, info.Updated)
if err != nil {
fs.Log(o, "Bad time decode: %v", err)
} else {
@ -491,7 +491,7 @@ func (o *FsObjectStorage) ModTime() time.Time {
// Returns metadata for an object
func metadataFromModTime(modTime time.Time) map[string]string {
metadata := make(map[string]string, 1)
metadata[metaMtime] = modTime.Format(RFC3339Out)
metadata[metaMtime] = modTime.Format(timeFormatOut)
return metadata
}
@ -559,7 +559,7 @@ func (o *FsObjectStorage) Update(in io.Reader, modTime time.Time, size int64) er
Name: o.storage.root + o.remote,
ContentType: contentType,
Size: uint64(size),
Updated: modTime.Format(RFC3339Out), // Doesn't get set
Updated: modTime.Format(timeFormatOut), // Doesn't get set
Metadata: metadataFromModTime(modTime),
}
newObject, err := o.storage.svc.Objects.Insert(o.storage.bucket, &object).Media(in).Name(object.Name).PredefinedAcl(o.storage.objectAcl).Do()

View File

@ -68,7 +68,7 @@ func (f *FsLocal) String() string {
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsLocal) NewFsObjectWithInfo(remote string, info os.FileInfo) fs.Object {
func (f *FsLocal) newFsObjectWithInfo(remote string, info os.FileInfo) fs.Object {
path := filepath.Join(f.root, remote)
o := &FsObjectLocal{local: f, remote: remote, path: path}
if info != nil {
@ -87,7 +87,7 @@ func (f *FsLocal) NewFsObjectWithInfo(remote string, info os.FileInfo) fs.Object
//
// May return nil if an error occurred
func (f *FsLocal) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// List the path returning a channel of FsObjects
@ -111,7 +111,7 @@ func (f *FsLocal) List() fs.ObjectsChan {
return nil
// remote = ""
}
if fs := f.NewFsObjectWithInfo(remote, fi); fs != nil {
if fs := f.newFsObjectWithInfo(remote, fi); fs != nil {
if fs.Storable() {
out <- fs
}

View File

@ -227,7 +227,7 @@ func NewFs(name, root string) (fs.Fs, error) {
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsS3) NewFsObjectWithInfo(remote string, info *s3.Key) fs.Object {
func (f *FsS3) newFsObjectWithInfo(remote string, info *s3.Key) fs.Object {
o := &FsObjectS3{
s3: f,
remote: remote,
@ -256,7 +256,7 @@ func (f *FsS3) NewFsObjectWithInfo(remote string, info *s3.Key) fs.Object {
//
// May return nil if an error occurred
func (f *FsS3) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// list the objects into the function supplied
@ -312,7 +312,7 @@ func (f *FsS3) List() fs.ObjectsChan {
go func() {
defer close(out)
f.list(false, func(remote string, object *s3.Key) {
if fs := f.NewFsObjectWithInfo(remote, object); fs != nil {
if fs := f.newFsObjectWithInfo(remote, object); fs != nil {
out <- fs
}
})

View File

@ -157,7 +157,7 @@ func NewFs(name, root string) (fs.Fs, error) {
// Return an FsObject from a path
//
// May return nil if an error occurred
func (f *FsSwift) NewFsObjectWithInfo(remote string, info *swift.Object) fs.Object {
func (f *FsSwift) newFsObjectWithInfo(remote string, info *swift.Object) fs.Object {
fs := &FsObjectSwift{
swift: f,
remote: remote,
@ -179,7 +179,7 @@ func (f *FsSwift) NewFsObjectWithInfo(remote string, info *swift.Object) fs.Obje
//
// May return nil if an error occurred
func (f *FsSwift) NewFsObject(remote string) fs.Object {
return f.NewFsObjectWithInfo(remote, nil)
return f.newFsObjectWithInfo(remote, nil)
}
// list the objects into the function supplied
@ -236,7 +236,7 @@ func (f *FsSwift) List() fs.ObjectsChan {
go func() {
defer close(out)
f.list(false, func(remote string, object *swift.Object) {
if fs := f.NewFsObjectWithInfo(remote, object); fs != nil {
if fs := f.newFsObjectWithInfo(remote, object); fs != nil {
out <- fs
}
})