Merge pull request #1323 from harshavardhana/share
share/list: clean share list
This commit is contained in:
@@ -102,19 +102,20 @@ func doShareDownloadURL(targetURL string, recursive bool, expiry time.Duration)
|
||||
incomplete := false
|
||||
for content := range clnt.List(recursive, incomplete) {
|
||||
if content.Err != nil {
|
||||
return content.Err.Trace()
|
||||
return content.Err.Trace(clnt.GetURL().String())
|
||||
}
|
||||
|
||||
objectURL := content.Content.URL.String()
|
||||
newClnt, err := url2Client(objectURL)
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
return err.Trace(objectURL)
|
||||
}
|
||||
|
||||
// Generate share URL.
|
||||
shareURL, err := newClnt.ShareDownload(expiry)
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
// add objectURL and expiry as part of the trace arguments.
|
||||
return err.Trace(objectURL, "expiry="+expiry.String())
|
||||
}
|
||||
|
||||
// Make new entries to shareDB.
|
||||
@@ -146,6 +147,7 @@ func mainShareDownload(ctx *cli.Context) {
|
||||
// Extract arguments.
|
||||
config := mustGetMcConfig()
|
||||
args := ctx.Args()
|
||||
// if recursive strip off the "..."
|
||||
url := stripRecursiveURL(args.First())
|
||||
isRecursive := isURLRecursive(args.First())
|
||||
expiry := shareDefaultExpiry
|
||||
@@ -156,9 +158,7 @@ func mainShareDownload(ctx *cli.Context) {
|
||||
fatalIf(probe.NewError(e), "Unable to parse expire=‘"+expireArg+"’.")
|
||||
}
|
||||
|
||||
targetURL := getAliasURL(stripRecursiveURL(url), config.Aliases) // Expand alias.
|
||||
|
||||
// if recursive strip off the "..."
|
||||
err := doShareDownloadURL(stripRecursiveURL(targetURL), isRecursive, expiry)
|
||||
targetURL := getAliasURL(url, config.Aliases) // Expand alias.
|
||||
err := doShareDownloadURL(targetURL, isRecursive, expiry)
|
||||
fatalIf(err.Trace(targetURL), "Unable to share target ‘"+args.First()+"’.")
|
||||
}
|
||||
|
||||
+19
-11
@@ -56,21 +56,29 @@ func checkShareListSyntax(ctx *cli.Context) {
|
||||
|
||||
// doShareList list shared url's.
|
||||
func doShareList(cmd string) *probe.Error {
|
||||
if cmd != "upload" && cmd != "download" {
|
||||
return probe.NewError(fmt.Errorf("Unknown argument ‘%s’ passed.", cmd))
|
||||
}
|
||||
|
||||
// Fetch defaults.
|
||||
uploadsFile := getShareUploadsFile()
|
||||
downloadsFile := getShareDownloadsFile()
|
||||
|
||||
// Load previously saved upload-shares.
|
||||
shareDB := newShareDBV1()
|
||||
switch cmd {
|
||||
case "upload":
|
||||
err := shareDB.Load(getShareUploadsFile())
|
||||
if err != nil {
|
||||
return err.Trace(getShareUploadsFile())
|
||||
|
||||
// if upload - read uploads file.
|
||||
if cmd == "upload" {
|
||||
if err := shareDB.Load(uploadsFile); err != nil {
|
||||
return err.Trace(uploadsFile)
|
||||
}
|
||||
case "download":
|
||||
err := shareDB.Load(getShareDownloadsFile())
|
||||
if err != nil {
|
||||
return err.Trace(getShareDownloadsFile())
|
||||
}
|
||||
|
||||
// if download - read downloads file.
|
||||
if cmd == "download" {
|
||||
if err := shareDB.Load(downloadsFile); err != nil {
|
||||
return err.Trace(downloadsFile)
|
||||
}
|
||||
default:
|
||||
return probe.NewError(fmt.Errorf("Unknown argument ‘%s’ passed.", cmd))
|
||||
}
|
||||
|
||||
// Print previously shared entries.
|
||||
|
||||
@@ -162,6 +162,7 @@ func mainShareUpload(ctx *cli.Context) {
|
||||
|
||||
args := ctx.Args()
|
||||
config := mustGetMcConfig()
|
||||
// if recursive strip off the "..."
|
||||
url := stripRecursiveURL(args.First())
|
||||
isRecursive := isURLRecursive(args.First())
|
||||
expireArg := ctx.String("expire")
|
||||
|
||||
Reference in New Issue
Block a user