1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-08 10:07:25 +02:00

Add Ext format when exporting files.

This commit is contained in:
chrislusf 2015-07-08 23:19:54 -07:00
parent 8d10b91cf3
commit 3476d31e50

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"text/template" "text/template"
@ -49,7 +50,7 @@ func init() {
var ( var (
output = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar, or just a \"-\" for stdout") output = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar, or just a \"-\" for stdout")
format = cmdExport.Flag.String("fileNameFormat", defaultFnFormat, "filename format, default to {{.Mime}}/{{.Id}}:{{.Name}}") format = cmdExport.Flag.String("fileNameFormat", defaultFnFormat, "filename formatted with {{.Mime}} {{.Id}} {{.Name}} {{.Ext}}")
newer = cmdExport.Flag.String("newer", "", "export only files newer than this time, default is all files. Must be specified in RFC3339 without timezone") newer = cmdExport.Flag.String("newer", "", "export only files newer than this time, default is all files. Must be specified in RFC3339 without timezone")
tarOutputFile *tar.Writer tarOutputFile *tar.Writer
@ -159,6 +160,7 @@ type nameParams struct {
Id uint64 Id uint64
Mime string Mime string
Key string Key string
Ext string
} }
func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) { func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) {
@ -166,10 +168,12 @@ func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (e
if tarOutputFile != nil { if tarOutputFile != nil {
fileNameTemplateBuffer.Reset() fileNameTemplateBuffer.Reset()
if err = fileNameTemplate.Execute(fileNameTemplateBuffer, if err = fileNameTemplate.Execute(fileNameTemplateBuffer,
nameParams{Name: string(n.Name), nameParams{
Name: string(n.Name),
Id: n.Id, Id: n.Id,
Mime: string(n.Mime), Mime: string(n.Mime),
Key: key, Key: key,
Ext: filepath.Ext(string(n.Name)),
}, },
); err != nil { ); err != nil {
return err return err