Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e9625733d | ||
|
|
1513d76ca9 | ||
|
|
87dc0bf80e | ||
|
|
69c0d33543 | ||
|
|
8d891755e0 | ||
|
|
a9cd7869eb | ||
|
|
c40ab338a3 | ||
|
|
0fcd10d793 | ||
|
|
b7b75c5f46 | ||
|
|
b97b7b8987 | ||
|
|
8f3d514e3b | ||
|
|
bb3c0d45f2 | ||
|
|
9ebde383d4 | ||
|
|
cfea4fdc75 | ||
|
|
dd47bdfeaa | ||
|
|
ec9b92cbb7 | ||
|
|
975423abe2 | ||
|
|
3dd971f673 |
+167
@@ -0,0 +1,167 @@
|
|||||||
|
project_name: mc
|
||||||
|
|
||||||
|
release:
|
||||||
|
name_template: "Version {{.Version}}"
|
||||||
|
disable: true
|
||||||
|
github:
|
||||||
|
owner: minio
|
||||||
|
name: mc
|
||||||
|
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
- GO111MODULE=on
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- make clean
|
||||||
|
- go generate ./...
|
||||||
|
- go mod tidy
|
||||||
|
- go mod download
|
||||||
|
|
||||||
|
builds:
|
||||||
|
-
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- darwin
|
||||||
|
- windows
|
||||||
|
- freebsd
|
||||||
|
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
- arm
|
||||||
|
- ppc64le
|
||||||
|
- s390x
|
||||||
|
|
||||||
|
goarm:
|
||||||
|
- 7
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
- goos: darwin
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: darwin
|
||||||
|
goarch: s390x
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm64
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
- goos: windows
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: windows
|
||||||
|
goarch: s390x
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm64
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: s390x
|
||||||
|
|
||||||
|
flags:
|
||||||
|
- -tags=kqueue
|
||||||
|
- -trimpath
|
||||||
|
|
||||||
|
ldflags:
|
||||||
|
- "-s -w -X github.com/minio/mc/cmd.Version={{.Version}} -X github.com/minio/mc/cmd.ReleaseTag={{.Tag}} -X github.com/minio/mc/cmd.CommitID={{.FullCommit}} -X github.com/minio/mc/cmd.ShortCommitID={{.ShortCommit}}"
|
||||||
|
|
||||||
|
archives:
|
||||||
|
-
|
||||||
|
format: binary
|
||||||
|
name_template: "{{ .Binary }}-release/{{ .Os }}-{{ .Arch }}/{{ .Binary }}.{{ .Version }}"
|
||||||
|
|
||||||
|
nfpms:
|
||||||
|
-
|
||||||
|
id: minio
|
||||||
|
package_name: mc
|
||||||
|
vendor: MinIO, Inc.
|
||||||
|
homepage: https://min.io/
|
||||||
|
maintainer: dev@min.io
|
||||||
|
description: MinIO Client (mc) provides a modern alternative to UNIX commands like ls, cat, cp, mirror, diff, find etc. It supports filesystems and Amazon S3 compatible cloud storage service (AWS Signature v2 and v4).
|
||||||
|
license: Apache 2.0
|
||||||
|
bindir: /usr/bin
|
||||||
|
formats:
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
overrides:
|
||||||
|
deb:
|
||||||
|
file_name_template: "{{ .Binary }}-release/debs/{{ .ProjectName }}-{{ .Version }}_{{ .Arch }}"
|
||||||
|
replacements:
|
||||||
|
arm: armv7
|
||||||
|
files:
|
||||||
|
"NOTICE": "/usr/share/mc/NOTICE"
|
||||||
|
"CREDITS": "/usr/share/mc/CREDITS"
|
||||||
|
"LICENSE": "/usr/share/mc/LICENSE"
|
||||||
|
"README.md": "/usr/share/mc/README.md"
|
||||||
|
rpm:
|
||||||
|
file_name_template: "{{ .Binary }}-release/rpms/{{ .ProjectName }}-{{ .Version }}.{{ .Arch }}"
|
||||||
|
replacements:
|
||||||
|
amd64: x86_64
|
||||||
|
arm64: aarch64
|
||||||
|
arm: armv7
|
||||||
|
files:
|
||||||
|
"NOTICE": "/usr/share/mc/NOTICE"
|
||||||
|
"CREDITS": "/usr/share/mc/CREDITS"
|
||||||
|
"LICENSE": "/usr/share/mc/LICENSE"
|
||||||
|
"README.md": "/usr/share/mc/README.md"
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
algorithm: sha256
|
||||||
|
|
||||||
|
signs:
|
||||||
|
-
|
||||||
|
signature: "${artifact}.asc"
|
||||||
|
cmd: "sh"
|
||||||
|
args:
|
||||||
|
- '-c'
|
||||||
|
- 'gpg --quiet --detach-sign -a ${artifact}'
|
||||||
|
artifacts: all
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- '^Update yaml files'
|
||||||
|
|
||||||
|
dockers:
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
dockerfile: Dockerfile.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}
|
||||||
|
- minio/mc:latest
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: ppc64le
|
||||||
|
dockerfile: Dockerfile.ppc64le.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-ppc64le
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: s390x
|
||||||
|
dockerfile: Dockerfile.s390x.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-s390x
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
goarm: ''
|
||||||
|
dockerfile: Dockerfile.arm64.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-arm64
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: '7'
|
||||||
|
dockerfile: Dockerfile.arm.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-arm
|
||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.13-alpine
|
FROM golang:1.13-alpine as build
|
||||||
|
|
||||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
@@ -11,12 +11,12 @@ RUN \
|
|||||||
git clone https://github.com/minio/mc && cd mc && \
|
git clone https://github.com/minio/mc && cd mc && \
|
||||||
go install -v -ldflags "$(go run buildscripts/gen-ldflags.go)"
|
go install -v -ldflags "$(go run buildscripts/gen-ldflags.go)"
|
||||||
|
|
||||||
FROM alpine:3.10
|
FROM alpine:3.12
|
||||||
|
|
||||||
COPY --from=0 /go/bin/mc /usr/bin/mc
|
COPY --from=build /go/bin/mc /usr/bin/mc
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
apk add --no-cache ca-certificates && \
|
apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/master/CREDITS
|
||||||
|
|
||||||
ENTRYPOINT ["mc"]
|
ENTRYPOINT ["mc"]
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM arm32v7/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM arm64v8/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
+3
-5
@@ -1,10 +1,8 @@
|
|||||||
FROM alpine:3.10
|
FROM alpine:3.12
|
||||||
|
|
||||||
COPY mc /usr/bin/
|
COPY mc /usr/bin/
|
||||||
|
COPY CREDITS /
|
||||||
|
|
||||||
RUN \
|
RUN apk add --no-cache ca-certificates
|
||||||
apk add --no-cache ca-certificates && \
|
|
||||||
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf \
|
|
||||||
chmod +x /usr/bin/mc
|
|
||||||
|
|
||||||
ENTRYPOINT ["mc"]
|
ENTRYPOINT ["mc"]
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM ppc64le/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
+5
-6
@@ -1,11 +1,10 @@
|
|||||||
FROM alpine:3.10
|
FROM alpine:3.12
|
||||||
|
|
||||||
MAINTAINER MinIO Inc <dev@min.io>
|
MAINTAINER MinIO Inc <dev@min.io>
|
||||||
|
|
||||||
RUN \
|
COPY mc /usr/bin/mc
|
||||||
apk add --no-cache ca-certificates && \
|
|
||||||
apk add --no-cache --virtual .build-deps curl && \
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/bin/mc && \
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
chmod +x /usr/bin/mc && apk del .build-deps
|
|
||||||
|
|
||||||
ENTRYPOINT ["mc"]
|
ENTRYPOINT ["mc"]
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM s390x/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
MinIO Client (C) 2014, 2015 MinIO, Inc.
|
MinIO Client (C) 2014-2020 MinIO, Inc.
|
||||||
|
|
||||||
This product includes software developed at MinIO, Inc.
|
This product includes software developed at MinIO, Inc.
|
||||||
(https://min.io/).
|
(https://min.io/).
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ function _init() {
|
|||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
## List of architectures and OS to test coss compilation.
|
## List of architectures and OS to test coss compilation.
|
||||||
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 linux/arm linux/386"
|
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 linux/arm linux/386 windows/amd64"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _build() {
|
function _build() {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ var adminBucketQuotaCmd = cli.Command{
|
|||||||
Name: "quota",
|
Name: "quota",
|
||||||
Usage: "Manage bucket quota",
|
Usage: "Manage bucket quota",
|
||||||
Action: mainAdminBucketQuota,
|
Action: mainAdminBucketQuota,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminQuotaFlags, globalFlags...),
|
Flags: append(adminQuotaFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminBucketCmd = cli.Command{
|
|||||||
Name: "bucket",
|
Name: "bucket",
|
||||||
Usage: "manage buckets defined in the MinIO server",
|
Usage: "manage buckets defined in the MinIO server",
|
||||||
Action: mainAdminBucket,
|
Action: mainAdminBucket,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminBucketQuotaCmd,
|
adminBucketQuotaCmd,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
var adminConfigExportCmd = cli.Command{
|
var adminConfigExportCmd = cli.Command{
|
||||||
Name: "export",
|
Name: "export",
|
||||||
Usage: "export all config keys to STDOUT",
|
Usage: "export all config keys to STDOUT",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigExport,
|
Action: mainAdminConfigExport,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
var adminConfigGetCmd = cli.Command{
|
var adminConfigGetCmd = cli.Command{
|
||||||
Name: "get",
|
Name: "get",
|
||||||
Usage: "interactively retrieve a config key parameters",
|
Usage: "interactively retrieve a config key parameters",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigGet,
|
Action: mainAdminConfigGet,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ var historyListFlags = []cli.Flag{
|
|||||||
var adminConfigHistoryCmd = cli.Command{
|
var adminConfigHistoryCmd = cli.Command{
|
||||||
Name: "history",
|
Name: "history",
|
||||||
Usage: "show all historic configuration changes",
|
Usage: "show all historic configuration changes",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigHistory,
|
Action: mainAdminConfigHistory,
|
||||||
Flags: append(append([]cli.Flag{}, globalFlags...), historyListFlags...),
|
Flags: append(append([]cli.Flag{}, globalFlags...), historyListFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
var adminConfigImportCmd = cli.Command{
|
var adminConfigImportCmd = cli.Command{
|
||||||
Name: "import",
|
Name: "import",
|
||||||
Usage: "import multiple config keys from STDIN",
|
Usage: "import multiple config keys from STDIN",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigImport,
|
Action: mainAdminConfigImport,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ var adminConfigEnvFlags = []cli.Flag{
|
|||||||
var adminConfigResetCmd = cli.Command{
|
var adminConfigResetCmd = cli.Command{
|
||||||
Name: "reset",
|
Name: "reset",
|
||||||
Usage: "interactively reset a config key parameters",
|
Usage: "interactively reset a config key parameters",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigReset,
|
Action: mainAdminConfigReset,
|
||||||
Flags: append(adminConfigEnvFlags, globalFlags...),
|
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import (
|
|||||||
var adminConfigRestoreCmd = cli.Command{
|
var adminConfigRestoreCmd = cli.Command{
|
||||||
Name: "restore",
|
Name: "restore",
|
||||||
Usage: "rollback back changes to a specific config history",
|
Usage: "rollback back changes to a specific config history",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigRestore,
|
Action: mainAdminConfigRestore,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import (
|
|||||||
var adminConfigSetCmd = cli.Command{
|
var adminConfigSetCmd = cli.Command{
|
||||||
Name: "set",
|
Name: "set",
|
||||||
Usage: "interactively set a config key parameters",
|
Usage: "interactively set a config key parameters",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminConfigSet,
|
Action: mainAdminConfigSet,
|
||||||
Flags: append(adminConfigEnvFlags, globalFlags...),
|
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminConfigCmd = cli.Command{
|
|||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "manage MinIO server configuration",
|
Usage: "manage MinIO server configuration",
|
||||||
Action: mainAdminConfig,
|
Action: mainAdminConfig,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminConfigGetCmd,
|
adminConfigGetCmd,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ var adminConsoleCmd = cli.Command{
|
|||||||
Name: "console",
|
Name: "console",
|
||||||
Usage: "show console logs for MinIO server",
|
Usage: "show console logs for MinIO server",
|
||||||
Action: mainAdminConsole,
|
Action: mainAdminConsole,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminConsoleFlags, globalFlags...),
|
Flags: append(adminConsoleFlags, globalFlags...),
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ var adminGroupAddCmd = cli.Command{
|
|||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "add users to a new or existing group",
|
Usage: "add users to a new or existing group",
|
||||||
Action: mainAdminGroupAdd,
|
Action: mainAdminGroupAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ var adminGroupDisableCmd = cli.Command{
|
|||||||
Name: "disable",
|
Name: "disable",
|
||||||
Usage: "Disable a group",
|
Usage: "Disable a group",
|
||||||
Action: mainAdminGroupEnableDisable,
|
Action: mainAdminGroupEnableDisable,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var adminGroupEnableCmd = cli.Command{
|
|||||||
Name: "enable",
|
Name: "enable",
|
||||||
Usage: "Enable a group",
|
Usage: "Enable a group",
|
||||||
Action: mainAdminGroupEnableDisable,
|
Action: mainAdminGroupEnableDisable,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminGroupInfoCmd = cli.Command{
|
|||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "display group info",
|
Usage: "display group info",
|
||||||
Action: mainAdminGroupInfo,
|
Action: mainAdminGroupInfo,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminGroupListCmd = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "display list of groups",
|
Usage: "display list of groups",
|
||||||
Action: mainAdminGroupList,
|
Action: mainAdminGroupList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var adminGroupRemoveCmd = cli.Command{
|
|||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove group or members from a group",
|
Usage: "remove group or members from a group",
|
||||||
Action: mainAdminGroupRemove,
|
Action: mainAdminGroupRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminGroupCmd = cli.Command{
|
|||||||
Name: "group",
|
Name: "group",
|
||||||
Usage: "manage groups",
|
Usage: "manage groups",
|
||||||
Action: mainAdminGroup,
|
Action: mainAdminGroup,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminGroupAddCmd,
|
adminGroupAddCmd,
|
||||||
|
|||||||
+2
-2
@@ -67,7 +67,7 @@ var adminHealCmd = cli.Command{
|
|||||||
Name: "heal",
|
Name: "heal",
|
||||||
Usage: "heal disks, buckets and objects on MinIO server",
|
Usage: "heal disks, buckets and objects on MinIO server",
|
||||||
Action: mainAdminHeal,
|
Action: mainAdminHeal,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminHealFlags, globalFlags...),
|
Flags: append(adminHealFlags, globalFlags...),
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
@@ -221,7 +221,7 @@ func mainAdminHeal(ctx *cli.Context) error {
|
|||||||
fatalIf(err.Trace(clnt.GetURL().String()), "Unable to create client for URL ", aliasedURL)
|
fatalIf(err.Trace(clnt.GetURL().String()), "Unable to create client for URL ", aliasedURL)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for content := range clnt.List(false, false, false, DirNone) {
|
for content := range clnt.List(globalContext, false, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
fatalIf(content.Err.Trace(clnt.GetURL().String()), "Unable to heal bucket `"+bucket+"`.")
|
fatalIf(content.Err.Trace(clnt.GetURL().String()), "Unable to heal bucket `"+bucket+"`.")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ var adminInfoCmd = cli.Command{
|
|||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "display MinIO server information",
|
Usage: "display MinIO server information",
|
||||||
Action: mainAdminInfo,
|
Action: mainAdminInfo,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var adminKMSKeyStatusCmd = cli.Command{
|
|||||||
Name: "status",
|
Name: "status",
|
||||||
Usage: "request status information for a KMS master key",
|
Usage: "request status information for a KMS master key",
|
||||||
Action: mainAdminKMSKeyStatus,
|
Action: mainAdminKMSKeyStatus,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminKMSKeyCmd = cli.Command{
|
|||||||
Name: "key",
|
Name: "key",
|
||||||
Usage: "Manage KMS master keys: Request key status information",
|
Usage: "Manage KMS master keys: Request key status information",
|
||||||
Action: mainAdminKMSKey,
|
Action: mainAdminKMSKey,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminKMSKeyStatusCmd,
|
adminKMSKeyStatusCmd,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminKMSCmd = cli.Command{
|
|||||||
Name: "kms",
|
Name: "kms",
|
||||||
Usage: "perform KMS management operations",
|
Usage: "perform KMS management operations",
|
||||||
Action: mainAdminKMS,
|
Action: mainAdminKMS,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminKMSKeyCmd,
|
adminKMSKeyCmd,
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ var adminCmd = cli.Command{
|
|||||||
Usage: "manage MinIO servers",
|
Usage: "manage MinIO servers",
|
||||||
Action: mainAdmin,
|
Action: mainAdmin,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: append(adminFlags, globalFlags...),
|
Flags: append(adminFlags, globalFlags...),
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminServiceCmd,
|
adminServiceCmd,
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ var adminOBDCmd = cli.Command{
|
|||||||
Name: "obd",
|
Name: "obd",
|
||||||
Usage: "run on-board diagnostics",
|
Usage: "run on-board diagnostics",
|
||||||
Action: mainAdminOBD,
|
Action: mainAdminOBD,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminOBDFlags, globalFlags...),
|
Flags: append(adminOBDFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ var adminPolicyAddCmd = cli.Command{
|
|||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "add new policy",
|
Usage: "add new policy",
|
||||||
Action: mainAdminPolicyAdd,
|
Action: mainAdminPolicyAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ var adminPolicyInfoCmd = cli.Command{
|
|||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "show info on a policy",
|
Usage: "show info on a policy",
|
||||||
Action: mainAdminPolicyInfo,
|
Action: mainAdminPolicyInfo,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminPolicyListCmd = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "list all policies",
|
Usage: "list all policies",
|
||||||
Action: mainAdminPolicyList,
|
Action: mainAdminPolicyList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminPolicyRemoveCmd = cli.Command{
|
|||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove policy",
|
Usage: "remove policy",
|
||||||
Action: mainAdminPolicyRemove,
|
Action: mainAdminPolicyRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var adminPolicySetCmd = cli.Command{
|
|||||||
Name: "set",
|
Name: "set",
|
||||||
Usage: "set IAM policy on a user or group",
|
Usage: "set IAM policy on a user or group",
|
||||||
Action: mainAdminPolicySet,
|
Action: mainAdminPolicySet,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminPolicyCmd = cli.Command{
|
|||||||
Name: "policy",
|
Name: "policy",
|
||||||
Usage: "manage policies defined in the MinIO server",
|
Usage: "manage policies defined in the MinIO server",
|
||||||
Action: mainAdminPolicy,
|
Action: mainAdminPolicy,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminPolicyAddCmd,
|
adminPolicyAddCmd,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ var adminProfileStartCmd = cli.Command{
|
|||||||
Name: "start",
|
Name: "start",
|
||||||
Usage: "start recording profile data",
|
Usage: "start recording profile data",
|
||||||
Action: mainAdminProfileStart,
|
Action: mainAdminProfileStart,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminProfileStartFlags, globalFlags...),
|
Flags: append(adminProfileStartFlags, globalFlags...),
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var adminProfileStopCmd = cli.Command{
|
|||||||
Name: "stop",
|
Name: "stop",
|
||||||
Usage: "stop and download profile data",
|
Usage: "stop and download profile data",
|
||||||
Action: mainAdminProfileStop,
|
Action: mainAdminProfileStop,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ var adminProfileCmd = cli.Command{
|
|||||||
Name: "profile",
|
Name: "profile",
|
||||||
Usage: "generate profile data for debugging purposes",
|
Usage: "generate profile data for debugging purposes",
|
||||||
Action: mainAdminProfile,
|
Action: mainAdminProfile,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminProfileStartCmd,
|
adminProfileStartCmd,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ var adminPrometheusGenerateCmd = cli.Command{
|
|||||||
Name: "generate",
|
Name: "generate",
|
||||||
Usage: "generates prometheus config",
|
Usage: "generates prometheus config",
|
||||||
Action: mainAdminPrometheusGenerate,
|
Action: mainAdminPrometheusGenerate,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminPrometheusCmd = cli.Command{
|
|||||||
Name: "prometheus",
|
Name: "prometheus",
|
||||||
Usage: "manages prometheus config",
|
Usage: "manages prometheus config",
|
||||||
Action: mainAdminPrometheus,
|
Action: mainAdminPrometheus,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var adminServiceRestartCmd = cli.Command{
|
|||||||
Name: "restart",
|
Name: "restart",
|
||||||
Usage: "restart all MinIO servers",
|
Usage: "restart all MinIO servers",
|
||||||
Action: mainAdminServiceRestart,
|
Action: mainAdminServiceRestart,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var adminServiceStopCmd = cli.Command{
|
|||||||
Name: "stop",
|
Name: "stop",
|
||||||
Usage: "stop MinIO server",
|
Usage: "stop MinIO server",
|
||||||
Action: mainAdminServiceStop,
|
Action: mainAdminServiceStop,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminServiceCmd = cli.Command{
|
|||||||
Name: "service",
|
Name: "service",
|
||||||
Usage: "restart and stop all MinIO servers",
|
Usage: "restart and stop all MinIO servers",
|
||||||
Action: mainAdminService,
|
Action: mainAdminService,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import (
|
|||||||
var adminTopLocksCmd = cli.Command{
|
var adminTopLocksCmd = cli.Command{
|
||||||
Name: "locks",
|
Name: "locks",
|
||||||
Usage: "Get a list of the 10 oldest locks on a MinIO cluster.",
|
Usage: "Get a list of the 10 oldest locks on a MinIO cluster.",
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Action: mainAdminTopLocks,
|
Action: mainAdminTopLocks,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminTopCmd = cli.Command{
|
|||||||
Name: "top",
|
Name: "top",
|
||||||
Usage: "provide top like statistics for MinIO",
|
Usage: "provide top like statistics for MinIO",
|
||||||
Action: mainAdminTop,
|
Action: mainAdminTop,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminTopLocksCmd,
|
adminTopLocksCmd,
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ var adminTraceCmd = cli.Command{
|
|||||||
Name: "trace",
|
Name: "trace",
|
||||||
Usage: "show http trace for MinIO server",
|
Usage: "show http trace for MinIO server",
|
||||||
Action: mainAdminTrace,
|
Action: mainAdminTrace,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(adminTraceFlags, globalFlags...),
|
Flags: append(adminTraceFlags, globalFlags...),
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ var adminServerUpdateCmd = cli.Command{
|
|||||||
Name: "update",
|
Name: "update",
|
||||||
Usage: "update all MinIO servers",
|
Usage: "update all MinIO servers",
|
||||||
Action: mainAdminServerUpdate,
|
Action: mainAdminServerUpdate,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ var adminUserAddCmd = cli.Command{
|
|||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "add a new user",
|
Usage: "add a new user",
|
||||||
Action: mainAdminUserAdd,
|
Action: mainAdminUserAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var adminUserDisableCmd = cli.Command{
|
|||||||
Name: "disable",
|
Name: "disable",
|
||||||
Usage: "disable user",
|
Usage: "disable user",
|
||||||
Action: mainAdminUserDisable,
|
Action: mainAdminUserDisable,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var adminUserEnableCmd = cli.Command{
|
|||||||
Name: "enable",
|
Name: "enable",
|
||||||
Usage: "enable user",
|
Usage: "enable user",
|
||||||
Action: mainAdminUserEnable,
|
Action: mainAdminUserEnable,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminUserInfoCmd = cli.Command{
|
|||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "display info of a user",
|
Usage: "display info of a user",
|
||||||
Action: mainAdminUserInfo,
|
Action: mainAdminUserInfo,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminUserListCmd = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "list all users",
|
Usage: "list all users",
|
||||||
Action: mainAdminUserList,
|
Action: mainAdminUserList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var adminUserRemoveCmd = cli.Command{
|
|||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove user",
|
Usage: "remove user",
|
||||||
Action: mainAdminUserRemove,
|
Action: mainAdminUserRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var adminUserCmd = cli.Command{
|
|||||||
Name: "user",
|
Name: "user",
|
||||||
Usage: "manage users",
|
Usage: "manage users",
|
||||||
Action: mainAdminUser,
|
Action: mainAdminUser,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
adminUserAddCmd,
|
adminUserAddCmd,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func completeS3Path(s3Path string) (prediction []string) {
|
|||||||
|
|
||||||
// List dirPath content and only pick elements that corresponds
|
// List dirPath content and only pick elements that corresponds
|
||||||
// to the path that we want to complete
|
// to the path that we want to complete
|
||||||
for content := range clnt.List(false, false, false, DirFirst) {
|
for content := range clnt.List(globalContext, false, false, false, DirFirst) {
|
||||||
cmplS3Path := alias + getKey(content)
|
cmplS3Path := alias + getKey(content)
|
||||||
if content.Type.IsDir() {
|
if content.Type.IsDir() {
|
||||||
if !strings.HasSuffix(cmplS3Path, "/") {
|
if !strings.HasSuffix(cmplS3Path, "/") {
|
||||||
|
|||||||
+16
-12
@@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -43,7 +44,7 @@ var catCmd = cli.Command{
|
|||||||
Name: "cat",
|
Name: "cat",
|
||||||
Usage: "display object contents",
|
Usage: "display object contents",
|
||||||
Action: mainCat,
|
Action: mainCat,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(append(catFlags, ioFlags...), globalFlags...),
|
Flags: append(append(catFlags, ioFlags...), globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -139,7 +140,7 @@ func checkCatSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// catURL displays contents of a URL to stdout.
|
// catURL displays contents of a URL to stdout.
|
||||||
func catURL(sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error {
|
func catURL(ctx context.Context, sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error {
|
||||||
var reader io.ReadCloser
|
var reader io.ReadCloser
|
||||||
size := int64(-1)
|
size := int64(-1)
|
||||||
switch sourceURL {
|
switch sourceURL {
|
||||||
@@ -152,11 +153,11 @@ func catURL(sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error
|
|||||||
// downloaded object is equal to the original one. FS files
|
// downloaded object is equal to the original one. FS files
|
||||||
// are ignored since some of them have zero size though they
|
// are ignored since some of them have zero size though they
|
||||||
// have contents like files under /proc.
|
// have contents like files under /proc.
|
||||||
client, content, err := url2Stat(sourceURL, false, encKeyDB)
|
client, content, err := url2Stat(ctx, sourceURL, false, encKeyDB)
|
||||||
if err == nil && client.GetURL().Type == objectStorage {
|
if err == nil && client.GetURL().Type == objectStorage {
|
||||||
size = content.Size
|
size = content.Size
|
||||||
}
|
}
|
||||||
if reader, err = getSourceStreamFromURL(sourceURL, encKeyDB); err != nil {
|
if reader, err = getSourceStreamFromURL(ctx, sourceURL, encKeyDB); err != nil {
|
||||||
return err.Trace(sourceURL)
|
return err.Trace(sourceURL)
|
||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
@@ -210,17 +211,20 @@ func catOut(r io.Reader, size int64) *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mainCat is the main entry point for cat command.
|
// mainCat is the main entry point for cat command.
|
||||||
func mainCat(ctx *cli.Context) error {
|
func mainCat(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelCat := context.WithCancel(globalContext)
|
||||||
|
defer cancelCat()
|
||||||
|
|
||||||
// Parse encryption keys per command.
|
// Parse encryption keys per command.
|
||||||
encKeyDB, err := getEncKeys(ctx)
|
encKeyDB, err := getEncKeys(cliCtx)
|
||||||
fatalIf(err, "Unable to parse encryption keys.")
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
|
|
||||||
// check 'cat' cli arguments.
|
// check 'cat' cli arguments.
|
||||||
checkCatSyntax(ctx)
|
checkCatSyntax(cliCtx)
|
||||||
|
|
||||||
// Set command flags from context.
|
// Set command flags from context.
|
||||||
stdinMode := false
|
stdinMode := false
|
||||||
if !ctx.Args().Present() {
|
if !cliCtx.Args().Present() {
|
||||||
stdinMode = true
|
stdinMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,11 +235,11 @@ func mainCat(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if Args contain `-`, we need to preserve its order specially.
|
// if Args contain `-`, we need to preserve its order specially.
|
||||||
args := []string(ctx.Args())
|
args := []string(cliCtx.Args())
|
||||||
if ctx.Args().First() == "-" {
|
if cliCtx.Args().First() == "-" {
|
||||||
for i, arg := range os.Args {
|
for i, arg := range os.Args {
|
||||||
if arg == "cat" {
|
if arg == "cat" {
|
||||||
// Overwrite ctx.Args with os.Args.
|
// Overwrite cliCtx.Args with os.Args.
|
||||||
args = os.Args[i+1:]
|
args = os.Args[i+1:]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -244,7 +248,7 @@ func mainCat(ctx *cli.Context) error {
|
|||||||
|
|
||||||
// Convert arguments to URLs: expand alias, fix format.
|
// Convert arguments to URLs: expand alias, fix format.
|
||||||
for _, url := range args {
|
for _, url := range args {
|
||||||
fatalIf(catURL(url, encKeyDB).Trace(url), "Unable to read from `"+url+"`.")
|
fatalIf(catURL(ctx, url, encKeyDB).Trace(url), "Unable to read from `"+url+"`.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+11
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* MinIO Client (C) 2017 MinIO, Inc.
|
* MinIO Client (C) 2017-2020 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,8 +26,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattn/go-ieproxy"
|
||||||
"github.com/minio/mc/pkg/httptracer"
|
"github.com/minio/mc/pkg/httptracer"
|
||||||
"github.com/minio/mc/pkg/probe"
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio-go/v6/pkg/credentials"
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -63,9 +65,15 @@ func NewAdminFactory() func(config *Config) (*madmin.AdminClient, *probe.Error)
|
|||||||
var api *madmin.AdminClient
|
var api *madmin.AdminClient
|
||||||
var found bool
|
var found bool
|
||||||
if api, found = clientCache[confSum]; !found {
|
if api, found = clientCache[confSum]; !found {
|
||||||
|
// Admin API only supports signature v4.
|
||||||
|
creds := credentials.NewStaticV4(config.AccessKey, config.SecretKey, config.SessionToken)
|
||||||
|
|
||||||
// Not found. Instantiate a new MinIO
|
// Not found. Instantiate a new MinIO
|
||||||
var e error
|
var e error
|
||||||
api, e = madmin.New(hostName, config.AccessKey, config.SecretKey, useTLS)
|
api, e = madmin.NewWithOptions(hostName, &madmin.Options{
|
||||||
|
Creds: creds,
|
||||||
|
Secure: useTLS,
|
||||||
|
})
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, probe.NewError(e)
|
return nil, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -83,7 +91,7 @@ func NewAdminFactory() func(config *Config) (*madmin.AdminClient, *probe.Error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var transport http.RoundTripper = &http.Transport{
|
var transport http.RoundTripper = &http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: ieproxy.GetProxyFunc(),
|
||||||
DialContext: (&net.Dialer{
|
DialContext: (&net.Dialer{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
KeepAlive: 15 * time.Second,
|
KeepAlive: 15 * time.Second,
|
||||||
|
|||||||
+85
-52
@@ -119,7 +119,7 @@ func (f *fsClient) GetURL() ClientURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select replies a stream of query results.
|
// Select replies a stream of query results.
|
||||||
func (f *fsClient) Select(expression string, sse encrypt.ServerSide, opts SelectObjectOpts) (io.ReadCloser, *probe.Error) {
|
func (f *fsClient) Select(ctx context.Context, expression string, sse encrypt.ServerSide, opts SelectObjectOpts) (io.ReadCloser, *probe.Error) {
|
||||||
return nil, probe.NewError(APINotImplemented{
|
return nil, probe.NewError(APINotImplemented{
|
||||||
API: "Select",
|
API: "Select",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -127,7 +127,7 @@ func (f *fsClient) Select(expression string, sse encrypt.ServerSide, opts Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Watches for all fs events on an input path.
|
// Watches for all fs events on an input path.
|
||||||
func (f *fsClient) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
func (f *fsClient) Watch(ctx context.Context, options WatchOptions) (*WatchObject, *probe.Error) {
|
||||||
eventChan := make(chan []EventInfo)
|
eventChan := make(chan []EventInfo)
|
||||||
errorChan := make(chan *probe.Error)
|
errorChan := make(chan *probe.Error)
|
||||||
doneChan := make(chan struct{})
|
doneChan := make(chan struct{})
|
||||||
@@ -223,29 +223,51 @@ func (f *fsClient) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func preserveAttributes(fd *os.File, attr map[string]string) *probe.Error {
|
func preserveAttributes(fd *os.File, attr map[string]string) *probe.Error {
|
||||||
mode, e := strconv.ParseUint(attr["mode"], 10, 32)
|
if val, ok := attr["mode"]; ok {
|
||||||
if e != nil {
|
mode, e := strconv.ParseUint(val, 0, 32)
|
||||||
return probe.NewError(e)
|
if e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to change the file mode.
|
||||||
|
if e := fd.Chmod(os.FileMode(mode)); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to change the file mode.
|
var uid, gid int
|
||||||
if e := fd.Chmod(os.FileMode(mode)); e != nil {
|
var gidExists, uidExists bool
|
||||||
return probe.NewError(e)
|
var e error
|
||||||
|
if val, ok := attr["uid"]; ok {
|
||||||
|
uid, e = strconv.Atoi(val)
|
||||||
|
if e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
uidExists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
uid, e := strconv.Atoi(attr["uid"])
|
if val, ok := attr["gid"]; ok {
|
||||||
if e != nil {
|
gid, e = strconv.Atoi(val)
|
||||||
return probe.NewError(e)
|
if e != nil {
|
||||||
}
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
gid, e := strconv.Atoi(attr["gid"])
|
gidExists = true
|
||||||
if e != nil {
|
|
||||||
return probe.NewError(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to change the owner.
|
// Attempt to change the owner.
|
||||||
if e := fd.Chown(uid, gid); e != nil {
|
if gidExists && uidExists {
|
||||||
return probe.NewError(e)
|
if e := fd.Chown(uid, gid); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
} else if uidExists {
|
||||||
|
if e := fd.Chown(uid, -1); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if e := fd.Chown(-1, gid); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -253,7 +275,7 @@ func preserveAttributes(fd *os.File, attr map[string]string) *probe.Error {
|
|||||||
|
|
||||||
/// Object operations.
|
/// Object operations.
|
||||||
|
|
||||||
func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]string, progress io.Reader) (int64, *probe.Error) {
|
func (f *fsClient) put(ctx context.Context, reader io.Reader, size int64, metadata map[string][]string, progress io.Reader, preserve bool) (int64, *probe.Error) {
|
||||||
// ContentType is not handled on purpose.
|
// ContentType is not handled on purpose.
|
||||||
// For filesystem this is a redundant information.
|
// For filesystem this is a redundant information.
|
||||||
|
|
||||||
@@ -289,7 +311,7 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
attr := make(map[string]string)
|
attr := make(map[string]string)
|
||||||
if len(metadata[metaDataKey]) != 0 {
|
if len(metadata[metaDataKey]) != 0 && preserve {
|
||||||
attr, e = parseAttribute(metadata[metaDataKey][0])
|
attr, e = parseAttribute(metadata[metaDataKey][0])
|
||||||
if e != nil {
|
if e != nil {
|
||||||
tmpFile.Close()
|
tmpFile.Close()
|
||||||
@@ -347,20 +369,31 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin
|
|||||||
return totalWritten, err.Trace(objectPartPath, objectPath)
|
return totalWritten, err.Trace(objectPartPath, objectPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(attr) != 0 {
|
if len(attr) != 0 && preserve {
|
||||||
atime, e := strconv.ParseInt(attr["atime"], 10, 64)
|
var atime, mtime int64
|
||||||
if e != nil {
|
var e error
|
||||||
return totalWritten, probe.NewError(e)
|
var atimeChanged, mtimeChanged bool
|
||||||
|
if val, ok := attr["atime"]; ok {
|
||||||
|
atime, e = strconv.ParseInt(val, 10, 64)
|
||||||
|
if e != nil {
|
||||||
|
return totalWritten, probe.NewError(e)
|
||||||
|
}
|
||||||
|
atimeChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
mtime, e := strconv.ParseInt(attr["mtime"], 10, 64)
|
if val, ok := attr["mtime"]; ok {
|
||||||
if e != nil {
|
mtime, e = strconv.ParseInt(val, 10, 64)
|
||||||
return totalWritten, probe.NewError(e)
|
if e != nil {
|
||||||
|
return totalWritten, probe.NewError(e)
|
||||||
|
}
|
||||||
|
mtimeChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to change the access and modify time
|
// Attempt to change the access and modify time
|
||||||
if e := os.Chtimes(objectPath, time.Unix(atime, 0), time.Unix(mtime, 0)); e != nil {
|
if atimeChanged && mtimeChanged {
|
||||||
return totalWritten, probe.NewError(e)
|
if e := os.Chtimes(objectPath, time.Unix(atime, 0), time.Unix(mtime, 0)); e != nil {
|
||||||
|
return totalWritten, probe.NewError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,17 +401,17 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Put - create a new file with metadata.
|
// Put - create a new file with metadata.
|
||||||
func (f *fsClient) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) {
|
func (f *fsClient) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart, preserve bool) (int64, *probe.Error) {
|
||||||
if metadata[metaDataKey] != "" {
|
if metadata[metaDataKey] != "" {
|
||||||
meta := make(map[string][]string)
|
meta := make(map[string][]string)
|
||||||
meta[metaDataKey] = append(meta[metaDataKey], metadata[metaDataKey])
|
meta[metaDataKey] = append(meta[metaDataKey], metadata[metaDataKey])
|
||||||
return f.put(reader, size, meta, progress)
|
return f.put(ctx, reader, size, meta, progress, preserve)
|
||||||
}
|
}
|
||||||
return f.put(reader, size, nil, progress)
|
return f.put(ctx, reader, size, nil, progress, preserve)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShareDownload - share download not implemented for filesystem.
|
// ShareDownload - share download not implemented for filesystem.
|
||||||
func (f *fsClient) ShareDownload(expires time.Duration) (string, *probe.Error) {
|
func (f *fsClient) ShareDownload(ctx context.Context, expires time.Duration) (string, *probe.Error) {
|
||||||
return "", probe.NewError(APINotImplemented{
|
return "", probe.NewError(APINotImplemented{
|
||||||
API: "ShareDownload",
|
API: "ShareDownload",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -394,7 +427,7 @@ func (f *fsClient) ShareUpload(startsWith bool, expires time.Duration, contentTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy - copy data from source to destination
|
// Copy - copy data from source to destination
|
||||||
func (f *fsClient) Copy(source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart bool) *probe.Error {
|
func (f *fsClient) Copy(ctx context.Context, source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart, preserve bool) *probe.Error {
|
||||||
rc, e := os.Open(source)
|
rc, e := os.Open(source)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err := f.toClientError(e, source)
|
err := f.toClientError(e, source)
|
||||||
@@ -403,14 +436,14 @@ func (f *fsClient) Copy(source string, size int64, progress io.Reader, srcSSE, t
|
|||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
|
||||||
destination := f.PathURL.Path
|
destination := f.PathURL.Path
|
||||||
if _, err := f.put(rc, size, map[string][]string{}, progress); err != nil {
|
if _, err := f.put(ctx, rc, size, map[string][]string{}, progress, preserve); err != nil {
|
||||||
return err.Trace(destination, source)
|
return err.Trace(destination, source)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns reader and any additional metadata.
|
// Get returns reader and any additional metadata.
|
||||||
func (f *fsClient) Get(sse encrypt.ServerSide) (io.ReadCloser, *probe.Error) {
|
func (f *fsClient) Get(ctx context.Context, sse encrypt.ServerSide) (io.ReadCloser, *probe.Error) {
|
||||||
fileData, e := os.Open(f.PathURL.Path)
|
fileData, e := os.Open(f.PathURL.Path)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err := f.toClientError(e, f.PathURL.Path)
|
err := f.toClientError(e, f.PathURL.Path)
|
||||||
@@ -464,7 +497,7 @@ func deleteFile(deletePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove - remove entry read from clientContent channel.
|
// Remove - remove entry read from clientContent channel.
|
||||||
func (f *fsClient) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan *probe.Error {
|
func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan *probe.Error {
|
||||||
errorCh := make(chan *probe.Error)
|
errorCh := make(chan *probe.Error)
|
||||||
|
|
||||||
// Goroutine reads from contentCh and removes the entry in content.
|
// Goroutine reads from contentCh and removes the entry in content.
|
||||||
@@ -503,7 +536,7 @@ func (f *fsClient) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List - list files and folders.
|
// List - list files and folders.
|
||||||
func (f *fsClient) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent {
|
func (f *fsClient) List(ctx context.Context, isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent {
|
||||||
contentCh := make(chan *ClientContent)
|
contentCh := make(chan *ClientContent)
|
||||||
filteredCh := make(chan *ClientContent)
|
filteredCh := make(chan *ClientContent)
|
||||||
|
|
||||||
@@ -877,7 +910,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan *ClientContent, isMetad
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeBucket - create a new bucket.
|
// MakeBucket - create a new bucket.
|
||||||
func (f *fsClient) MakeBucket(region string, ignoreExisting, withLock bool) *probe.Error {
|
func (f *fsClient) MakeBucket(ctx context.Context, region string, ignoreExisting, withLock bool) *probe.Error {
|
||||||
// TODO: ignoreExisting has no effect currently. In the future, we want
|
// TODO: ignoreExisting has no effect currently. In the future, we want
|
||||||
// to call os.Mkdir() when ignoredExisting is disabled and os.MkdirAll()
|
// to call os.Mkdir() when ignoredExisting is disabled and os.MkdirAll()
|
||||||
// otherwise.
|
// otherwise.
|
||||||
@@ -890,7 +923,7 @@ func (f *fsClient) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set object lock configuration of bucket.
|
// Set object lock configuration of bucket.
|
||||||
func (f *fsClient) SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
func (f *fsClient) SetObjectLockConfig(ctx context.Context, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "SetObjectLockConfig",
|
API: "SetObjectLockConfig",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -898,7 +931,7 @@ func (f *fsClient) SetObjectLockConfig(mode minio.RetentionMode, validity uint64
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get object lock configuration of bucket.
|
// Get object lock configuration of bucket.
|
||||||
func (f *fsClient) GetObjectLockConfig() (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, err *probe.Error) {
|
func (f *fsClient) GetObjectLockConfig(ctx context.Context) (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, err *probe.Error) {
|
||||||
return "", 0, "", probe.NewError(APINotImplemented{
|
return "", 0, "", probe.NewError(APINotImplemented{
|
||||||
API: "GetObjectLockConfig",
|
API: "GetObjectLockConfig",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -906,7 +939,7 @@ func (f *fsClient) GetObjectLockConfig() (mode minio.RetentionMode, validity uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessRules - unsupported API
|
// GetAccessRules - unsupported API
|
||||||
func (f *fsClient) GetAccessRules() (map[string]string, *probe.Error) {
|
func (f *fsClient) GetAccessRules(ctx context.Context) (map[string]string, *probe.Error) {
|
||||||
return map[string]string{}, probe.NewError(APINotImplemented{
|
return map[string]string{}, probe.NewError(APINotImplemented{
|
||||||
API: "GetBucketPolicy",
|
API: "GetBucketPolicy",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -914,7 +947,7 @@ func (f *fsClient) GetAccessRules() (map[string]string, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set object retention for a given object.
|
// Set object retention for a given object.
|
||||||
func (f *fsClient) PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
func (f *fsClient) PutObjectRetention(ctx context.Context, mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "PutObjectRetention",
|
API: "PutObjectRetention",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -922,7 +955,7 @@ func (f *fsClient) PutObjectRetention(mode minio.RetentionMode, retainUntilDate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set object legal hold for a given object.
|
// Set object legal hold for a given object.
|
||||||
func (f *fsClient) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error {
|
func (f *fsClient) PutObjectLegalHold(ctx context.Context, lhold minio.LegalHoldStatus) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "PutObjectLegalHold",
|
API: "PutObjectLegalHold",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -930,7 +963,7 @@ func (f *fsClient) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccess - get access policy permissions.
|
// GetAccess - get access policy permissions.
|
||||||
func (f *fsClient) GetAccess() (access string, policyJSON string, err *probe.Error) {
|
func (f *fsClient) GetAccess(ctx context.Context) (access string, policyJSON string, err *probe.Error) {
|
||||||
// For windows this feature is not implemented.
|
// For windows this feature is not implemented.
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
|
||||||
@@ -955,7 +988,7 @@ func (f *fsClient) GetAccess() (access string, policyJSON string, err *probe.Err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAccess - set access policy permissions.
|
// SetAccess - set access policy permissions.
|
||||||
func (f *fsClient) SetAccess(access string, isJSON bool) *probe.Error {
|
func (f *fsClient) SetAccess(ctx context.Context, access string, isJSON bool) *probe.Error {
|
||||||
// For windows this feature is not implemented.
|
// For windows this feature is not implemented.
|
||||||
// JSON policy for fs is not yet implemented.
|
// JSON policy for fs is not yet implemented.
|
||||||
if runtime.GOOS == "windows" || isJSON {
|
if runtime.GOOS == "windows" || isJSON {
|
||||||
@@ -987,7 +1020,7 @@ func (f *fsClient) SetAccess(access string, isJSON bool) *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stat - get metadata from path.
|
// Stat - get metadata from path.
|
||||||
func (f *fsClient) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error) {
|
func (f *fsClient) Stat(ctx context.Context, isIncomplete, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error) {
|
||||||
st, err := f.fsStat(isIncomplete)
|
st, err := f.fsStat(isIncomplete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(f.PathURL.String())
|
return nil, err.Trace(f.PathURL.String())
|
||||||
@@ -1063,7 +1096,7 @@ func (f *fsClient) AddUserAgent(_, _ string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get Object Tags
|
// Get Object Tags
|
||||||
func (f *fsClient) GetTags() (*tags.Tags, *probe.Error) {
|
func (f *fsClient) GetTags(ctx context.Context) (*tags.Tags, *probe.Error) {
|
||||||
return nil, probe.NewError(APINotImplemented{
|
return nil, probe.NewError(APINotImplemented{
|
||||||
API: "GetObjectTagging",
|
API: "GetObjectTagging",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -1071,7 +1104,7 @@ func (f *fsClient) GetTags() (*tags.Tags, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set Object tags
|
// Set Object tags
|
||||||
func (f *fsClient) SetTags(tags string) *probe.Error {
|
func (f *fsClient) SetTags(ctx context.Context, tags string) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "SetObjectTagging",
|
API: "SetObjectTagging",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -1079,7 +1112,7 @@ func (f *fsClient) SetTags(tags string) *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete object tags
|
// Delete object tags
|
||||||
func (f *fsClient) DeleteTags() *probe.Error {
|
func (f *fsClient) DeleteTags(ctx context.Context) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "DeleteObjectTagging",
|
API: "DeleteObjectTagging",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -1087,7 +1120,7 @@ func (f *fsClient) DeleteTags() *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get lifecycle configuration for a given bucket, not implemented.
|
// Get lifecycle configuration for a given bucket, not implemented.
|
||||||
func (f *fsClient) GetLifecycle() (ilm.LifecycleConfiguration, *probe.Error) {
|
func (f *fsClient) GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error) {
|
||||||
return ilm.LifecycleConfiguration{}, probe.NewError(APINotImplemented{
|
return ilm.LifecycleConfiguration{}, probe.NewError(APINotImplemented{
|
||||||
API: "GetLifecycle",
|
API: "GetLifecycle",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
@@ -1095,7 +1128,7 @@ func (f *fsClient) GetLifecycle() (ilm.LifecycleConfiguration, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set lifecycle configuration for a given bucket, not implemented.
|
// Set lifecycle configuration for a given bucket, not implemented.
|
||||||
func (f *fsClient) SetLifecycle(_ ilm.LifecycleConfiguration) *probe.Error {
|
func (f *fsClient) SetLifecycle(ctx context.Context, _ ilm.LifecycleConfiguration) *probe.Error {
|
||||||
return probe.NewError(APINotImplemented{
|
return probe.NewError(APINotImplemented{
|
||||||
API: "SetLifecycle",
|
API: "SetLifecycle",
|
||||||
APIType: "filesystem",
|
APIType: "filesystem",
|
||||||
|
|||||||
+23
-23
@@ -45,7 +45,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
var n int64
|
var n int64
|
||||||
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
reader = bytes.NewReader([]byte(data))
|
reader = bytes.NewReader([]byte(data))
|
||||||
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
|
|
||||||
// Verify previously create files and list them.
|
// Verify previously create files and list them.
|
||||||
var contents []*ClientContent
|
var contents []*ClientContent
|
||||||
for content := range fsClient.List(false, false, false, DirNone) {
|
for content := range fsClient.List(globalContext, false, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
err = content.Err
|
err = content.Err
|
||||||
break
|
break
|
||||||
@@ -84,7 +84,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
reader = bytes.NewReader([]byte(data))
|
reader = bytes.NewReader([]byte(data))
|
||||||
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
|
|
||||||
contents = nil
|
contents = nil
|
||||||
// List non recursive to list only top level files.
|
// List non recursive to list only top level files.
|
||||||
for content := range fsClient.List(false, false, false, DirNone) {
|
for content := range fsClient.List(globalContext, false, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
err = content.Err
|
err = content.Err
|
||||||
break
|
break
|
||||||
@@ -109,7 +109,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
|
|
||||||
contents = nil
|
contents = nil
|
||||||
// List recursively all files and verify.
|
// List recursively all files and verify.
|
||||||
for content := range fsClient.List(true, false, false, DirNone) {
|
for content := range fsClient.List(globalContext, true, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
err = content.Err
|
err = content.Err
|
||||||
break
|
break
|
||||||
@@ -144,7 +144,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
reader = bytes.NewReader([]byte(data))
|
reader = bytes.NewReader([]byte(data))
|
||||||
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ func (s *TestSuite) TestList(c *C) {
|
|||||||
|
|
||||||
contents = nil
|
contents = nil
|
||||||
// List recursively all files and verify.
|
// List recursively all files and verify.
|
||||||
for content := range fsClient.List(true, false, false, DirNone) {
|
for content := range fsClient.List(globalContext, true, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
err = content.Err
|
err = content.Err
|
||||||
break
|
break
|
||||||
@@ -194,7 +194,7 @@ func (s *TestSuite) TestPutBucket(c *C) {
|
|||||||
bucketPath := filepath.Join(root, "bucket")
|
bucketPath := filepath.Join(root, "bucket")
|
||||||
fsClient, err := fsNew(bucketPath)
|
fsClient, err := fsNew(bucketPath)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
err = fsClient.MakeBucket("us-east-1", true, false)
|
err = fsClient.MakeBucket(context.Background(), "us-east-1", true, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,9 +208,9 @@ func (s *TestSuite) TestStatBucket(c *C) {
|
|||||||
|
|
||||||
fsClient, err := fsNew(bucketPath)
|
fsClient, err := fsNew(bucketPath)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
err = fsClient.MakeBucket("us-east-1", true, false)
|
err = fsClient.MakeBucket(context.Background(), "us-east-1", true, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
_, err = fsClient.Stat(false, false, nil)
|
_, err = fsClient.Stat(context.Background(), false, false, nil)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,15 +223,15 @@ func (s *TestSuite) TestBucketACLFails(c *C) {
|
|||||||
bucketPath := filepath.Join(root, "bucket")
|
bucketPath := filepath.Join(root, "bucket")
|
||||||
fsClient, err := fsNew(bucketPath)
|
fsClient, err := fsNew(bucketPath)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
err = fsClient.MakeBucket("us-east-1", true, false)
|
err = fsClient.MakeBucket(context.Background(), "us-east-1", true, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
// On windows setting permissions is not supported.
|
// On windows setting permissions is not supported.
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
err = fsClient.SetAccess("readonly", false)
|
err = fsClient.SetAccess(context.Background(), "readonly", false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
_, _, err = fsClient.GetAccess()
|
_, _, err = fsClient.GetAccess(context.Background())
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ func (s *TestSuite) TestPut(c *C) {
|
|||||||
var n int64
|
var n int64
|
||||||
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err = fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
}
|
}
|
||||||
@@ -271,11 +271,11 @@ func (s *TestSuite) TestGet(c *C) {
|
|||||||
reader = bytes.NewReader([]byte(data))
|
reader = bytes.NewReader([]byte(data))
|
||||||
n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
reader, err = fsClient.Get(nil)
|
reader, err = fsClient.Get(context.Background(), nil)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
var results bytes.Buffer
|
var results bytes.Buffer
|
||||||
_, e = io.Copy(&results, reader)
|
_, e = io.Copy(&results, reader)
|
||||||
@@ -299,11 +299,11 @@ func (s *TestSuite) TestGetRange(c *C) {
|
|||||||
reader = bytes.NewReader([]byte(data))
|
reader = bytes.NewReader([]byte(data))
|
||||||
n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err := fsClient.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
reader, err = fsClient.Get(nil)
|
reader, err = fsClient.Get(context.Background(), nil)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
var results bytes.Buffer
|
var results bytes.Buffer
|
||||||
buf := make([]byte, 5)
|
buf := make([]byte, 5)
|
||||||
@@ -330,11 +330,11 @@ func (s *TestSuite) TestStatObject(c *C) {
|
|||||||
reader := bytes.NewReader([]byte(data))
|
reader := bytes.NewReader([]byte(data))
|
||||||
n, err := fsClient.Put(context.Background(), reader, int64(dataLen), map[string]string{
|
n, err := fsClient.Put(context.Background(), reader, int64(dataLen), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
content, err := fsClient.Stat(false, false, nil)
|
content, err := fsClient.Stat(context.Background(), false, false, nil)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(content.Size, Equals, int64(dataLen))
|
c.Assert(content.Size, Equals, int64(dataLen))
|
||||||
}
|
}
|
||||||
@@ -355,10 +355,10 @@ func (s *TestSuite) TestCopy(c *C) {
|
|||||||
reader := bytes.NewReader([]byte(data))
|
reader := bytes.NewReader([]byte(data))
|
||||||
n, err := fsClientSource.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
n, err := fsClientSource.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(data)))
|
c.Assert(n, Equals, int64(len(data)))
|
||||||
|
|
||||||
err = fsClientTarget.Copy(sourcePath, int64(len(data)), nil, nil, nil, nil, false)
|
err = fsClientTarget.Copy(context.Background(), sourcePath, int64(len(data)), nil, nil, nil, nil, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|||||||
+123
-116
@@ -37,6 +37,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattn/go-ieproxy"
|
||||||
"github.com/minio/mc/cmd/ilm"
|
"github.com/minio/mc/cmd/ilm"
|
||||||
"github.com/minio/mc/pkg/httptracer"
|
"github.com/minio/mc/pkg/httptracer"
|
||||||
"github.com/minio/mc/pkg/probe"
|
"github.com/minio/mc/pkg/probe"
|
||||||
@@ -149,7 +150,7 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: ieproxy.GetProxyFunc(),
|
||||||
DialContext: (&net.Dialer{
|
DialContext: (&net.Dialer{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
KeepAlive: 15 * time.Second,
|
KeepAlive: 15 * time.Second,
|
||||||
@@ -232,7 +233,7 @@ func (c *S3Client) GetURL() ClientURL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddNotificationConfig - Add bucket notification
|
// AddNotificationConfig - Add bucket notification
|
||||||
func (c *S3Client) AddNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
|
func (c *S3Client) AddNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
// Validate total fields in ARN.
|
// Validate total fields in ARN.
|
||||||
fields := strings.Split(arn, ":")
|
fields := strings.Split(arn, ":")
|
||||||
@@ -241,7 +242,7 @@ func (c *S3Client) AddNotificationConfig(arn string, events []string, prefix, su
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get any enabled notification.
|
// Get any enabled notification.
|
||||||
mb, e := c.api.GetBucketNotification(bucket)
|
mb, e := c.api.GetBucketNotificationWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -297,17 +298,17 @@ func (c *S3Client) AddNotificationConfig(arn string, events []string, prefix, su
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveNotificationConfig - Remove bucket notification
|
// RemoveNotificationConfig - Remove bucket notification
|
||||||
func (c *S3Client) RemoveNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error {
|
func (c *S3Client) RemoveNotificationConfig(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
// Remove all notification configs if arn is empty
|
// Remove all notification configs if arn is empty
|
||||||
if arn == "" {
|
if arn == "" {
|
||||||
if err := c.api.RemoveAllBucketNotification(bucket); err != nil {
|
if err := c.api.RemoveAllBucketNotificationWithContext(ctx, bucket); err != nil {
|
||||||
return probe.NewError(err)
|
return probe.NewError(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mb, e := c.api.GetBucketNotification(bucket)
|
mb, e := c.api.GetBucketNotificationWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -383,10 +384,10 @@ type NotificationConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListNotificationConfigs - List notification configs
|
// ListNotificationConfigs - List notification configs
|
||||||
func (c *S3Client) ListNotificationConfigs(arn string) ([]NotificationConfig, *probe.Error) {
|
func (c *S3Client) ListNotificationConfigs(ctx context.Context, arn string) ([]NotificationConfig, *probe.Error) {
|
||||||
var configs []NotificationConfig
|
var configs []NotificationConfig
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
mb, e := c.api.GetBucketNotification(bucket)
|
mb, e := c.api.GetBucketNotificationWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, probe.NewError(e)
|
return nil, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -607,7 +608,7 @@ func selectCompressionType(selOpts SelectObjectOpts, object string) minio.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select - select object content wrapper.
|
// Select - select object content wrapper.
|
||||||
func (c *S3Client) Select(expression string, sse encrypt.ServerSide, selOpts SelectObjectOpts) (io.ReadCloser, *probe.Error) {
|
func (c *S3Client) Select(ctx context.Context, expression string, sse encrypt.ServerSide, selOpts SelectObjectOpts) (io.ReadCloser, *probe.Error) {
|
||||||
opts := minio.SelectObjectOptions{
|
opts := minio.SelectObjectOptions{
|
||||||
Expression: expression,
|
Expression: expression,
|
||||||
ExpressionType: minio.QueryExpressionTypeSQL,
|
ExpressionType: minio.QueryExpressionTypeSQL,
|
||||||
@@ -619,7 +620,7 @@ func (c *S3Client) Select(expression string, sse encrypt.ServerSide, selOpts Sel
|
|||||||
|
|
||||||
opts.InputSerialization = selectObjectInputOpts(selOpts, object)
|
opts.InputSerialization = selectObjectInputOpts(selOpts, object)
|
||||||
opts.OutputSerialization = selectObjectOutputOpts(selOpts, opts.InputSerialization)
|
opts.OutputSerialization = selectObjectOutputOpts(selOpts, opts.InputSerialization)
|
||||||
reader, e := c.api.SelectObjectContent(context.Background(), bucket, object, opts)
|
reader, e := c.api.SelectObjectContent(ctx, bucket, object, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, probe.NewError(e)
|
return nil, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -728,7 +729,7 @@ func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []Even
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Watch - Start watching on all bucket events for a given account ID.
|
// Watch - Start watching on all bucket events for a given account ID.
|
||||||
func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
func (c *S3Client) Watch(ctx context.Context, options WatchOptions) (*WatchObject, *probe.Error) {
|
||||||
// Extract bucket and object.
|
// Extract bucket and object.
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
|
|
||||||
@@ -756,7 +757,7 @@ func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
|||||||
// The list of buckets to watch
|
// The list of buckets to watch
|
||||||
var buckets []string
|
var buckets []string
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
bkts, err := c.api.ListBuckets()
|
bkts, err := c.api.ListBucketsWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, probe.NewError(err)
|
return nil, probe.NewError(err)
|
||||||
}
|
}
|
||||||
@@ -780,7 +781,7 @@ func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// Start listening on all bucket events.
|
// Start listening on all bucket events.
|
||||||
eventsCh := c.api.ListenBucketNotification(bucket, options.Prefix, options.Suffix, events, wo.DoneChan)
|
eventsCh := c.api.ListenBucketNotificationWithContext(ctx, bucket, options.Prefix, options.Suffix, events, wo.DoneChan)
|
||||||
for notificationInfo := range eventsCh {
|
for notificationInfo := range eventsCh {
|
||||||
if notificationInfo.Err != nil {
|
if notificationInfo.Err != nil {
|
||||||
var perr *probe.Error
|
var perr *probe.Error
|
||||||
@@ -811,11 +812,11 @@ func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get - get object with metadata.
|
// Get - get object with metadata.
|
||||||
func (c *S3Client) Get(sse encrypt.ServerSide) (io.ReadCloser, *probe.Error) {
|
func (c *S3Client) Get(ctx context.Context, sse encrypt.ServerSide) (io.ReadCloser, *probe.Error) {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
opts := minio.GetObjectOptions{}
|
opts := minio.GetObjectOptions{}
|
||||||
opts.ServerSideEncryption = sse
|
opts.ServerSideEncryption = sse
|
||||||
reader, e := c.api.GetObject(bucket, object, opts)
|
reader, e := c.api.GetObjectWithContext(ctx, bucket, object, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
errResponse := minio.ToErrorResponse(e)
|
errResponse := minio.ToErrorResponse(e)
|
||||||
if errResponse.Code == "NoSuchBucket" {
|
if errResponse.Code == "NoSuchBucket" {
|
||||||
@@ -839,7 +840,7 @@ func (c *S3Client) Get(sse encrypt.ServerSide) (io.ReadCloser, *probe.Error) {
|
|||||||
// Copy - copy object, uses server side copy API. Also uses an abstracted API
|
// Copy - copy object, uses server side copy API. Also uses an abstracted API
|
||||||
// such that large file sizes will be copied in multipart manner on server
|
// such that large file sizes will be copied in multipart manner on server
|
||||||
// side.
|
// side.
|
||||||
func (c *S3Client) Copy(source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart bool) *probe.Error {
|
func (c *S3Client) Copy(ctx context.Context, source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart, isPreserve bool) *probe.Error {
|
||||||
dstBucket, dstObject := c.url2BucketAndObject()
|
dstBucket, dstObject := c.url2BucketAndObject()
|
||||||
if dstBucket == "" {
|
if dstBucket == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
@@ -881,9 +882,9 @@ func (c *S3Client) Copy(source string, size int64, progress io.Reader, srcSSE, t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if disableMultipart {
|
if disableMultipart {
|
||||||
e = c.api.CopyObjectWithProgress(dst, src, progress)
|
e = c.api.CopyObjectWithProgressWithContext(ctx, dst, src, progress)
|
||||||
} else {
|
} else {
|
||||||
e = c.api.ComposeObjectWithProgress(dst, []minio.SourceInfo{src}, progress)
|
e = c.api.ComposeObjectWithProgressWithContext(ctx, dst, []minio.SourceInfo{src}, progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@@ -912,7 +913,7 @@ func (c *S3Client) Copy(source string, size int64, progress io.Reader, srcSSE, t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Put - upload an object with custom metadata.
|
// Put - upload an object with custom metadata.
|
||||||
func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) {
|
func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart, isPreserve bool) (int64, *probe.Error) {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return 0, probe.NewError(BucketNameEmpty{})
|
return 0, probe.NewError(BucketNameEmpty{})
|
||||||
@@ -987,13 +988,19 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metada
|
|||||||
|
|
||||||
if lockModeStr != "" {
|
if lockModeStr != "" {
|
||||||
opts.Mode = &lockMode
|
opts.Mode = &lockMode
|
||||||
|
opts.SendContentMd5 = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if lh, ok := metadata[AmzObjectLockLegalHold]; ok {
|
if lh, ok := metadata[AmzObjectLockLegalHold]; ok {
|
||||||
delete(metadata, AmzObjectLockLegalHold)
|
delete(metadata, AmzObjectLockLegalHold)
|
||||||
opts.LegalHold = minio.LegalHoldStatus(strings.ToUpper(lh))
|
opts.LegalHold = minio.LegalHoldStatus(strings.ToUpper(lh))
|
||||||
|
opts.SendContentMd5 = true
|
||||||
|
}
|
||||||
|
if opts.LegalHold == "" && opts.Mode == nil {
|
||||||
|
if _, _, _, err := c.api.GetBucketObjectLockConfig(bucket); err == nil {
|
||||||
|
opts.SendContentMd5 = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n, e := c.api.PutObjectWithContext(ctx, bucket, object, reader, size, opts)
|
n, e := c.api.PutObjectWithContext(ctx, bucket, object, reader, size, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
errResponse := minio.ToErrorResponse(e)
|
errResponse := minio.ToErrorResponse(e)
|
||||||
@@ -1037,7 +1044,7 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metada
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove incomplete uploads.
|
// Remove incomplete uploads.
|
||||||
func (c *S3Client) removeIncompleteObjects(bucket string, objectsCh <-chan string) <-chan minio.RemoveObjectError {
|
func (c *S3Client) removeIncompleteObjects(ctx context.Context, bucket string, objectsCh <-chan string) <-chan minio.RemoveObjectError {
|
||||||
removeObjectErrorCh := make(chan minio.RemoveObjectError)
|
removeObjectErrorCh := make(chan minio.RemoveObjectError)
|
||||||
|
|
||||||
// Goroutine reads from objectsCh and sends error to removeObjectErrorCh if any.
|
// Goroutine reads from objectsCh and sends error to removeObjectErrorCh if any.
|
||||||
@@ -1045,7 +1052,7 @@ func (c *S3Client) removeIncompleteObjects(bucket string, objectsCh <-chan strin
|
|||||||
defer close(removeObjectErrorCh)
|
defer close(removeObjectErrorCh)
|
||||||
|
|
||||||
for object := range objectsCh {
|
for object := range objectsCh {
|
||||||
if err := c.api.RemoveIncompleteUpload(bucket, object); err != nil {
|
if err := c.api.RemoveIncompleteUploadWithContext(ctx, bucket, object); err != nil {
|
||||||
removeObjectErrorCh <- minio.RemoveObjectError{ObjectName: object, Err: err}
|
removeObjectErrorCh <- minio.RemoveObjectError{ObjectName: object, Err: err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1060,7 +1067,7 @@ func (c *S3Client) AddUserAgent(app string, version string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove - remove object or bucket(s).
|
// Remove - remove object or bucket(s).
|
||||||
func (c *S3Client) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan *probe.Error {
|
func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan *probe.Error {
|
||||||
errorCh := make(chan *probe.Error)
|
errorCh := make(chan *probe.Error)
|
||||||
|
|
||||||
prevBucket := ""
|
prevBucket := ""
|
||||||
@@ -1094,9 +1101,9 @@ func (c *S3Client) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh
|
|||||||
objectsCh = make(chan string)
|
objectsCh = make(chan string)
|
||||||
prevBucket = bucket
|
prevBucket = bucket
|
||||||
if isIncomplete {
|
if isIncomplete {
|
||||||
statusCh = c.removeIncompleteObjects(bucket, objectsCh)
|
statusCh = c.removeIncompleteObjects(ctx, bucket, objectsCh)
|
||||||
} else {
|
} else {
|
||||||
statusCh = c.api.RemoveObjectsWithOptions(bucket, objectsCh, opts)
|
statusCh = c.api.RemoveObjectsWithOptionsContext(ctx, bucket, objectsCh, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1109,16 +1116,16 @@ func (c *S3Client) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh
|
|||||||
}
|
}
|
||||||
// Remove bucket if it qualifies.
|
// Remove bucket if it qualifies.
|
||||||
if isRemoveBucket && !isIncomplete {
|
if isRemoveBucket && !isIncomplete {
|
||||||
if err := c.api.RemoveBucket(prevBucket); err != nil {
|
if err := c.api.RemoveBucketWithContext(ctx, prevBucket); err != nil {
|
||||||
errorCh <- probe.NewError(err)
|
errorCh <- probe.NewError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Re-init objectsCh for next bucket
|
// Re-init objectsCh for next bucket
|
||||||
objectsCh = make(chan string)
|
objectsCh = make(chan string)
|
||||||
if isIncomplete {
|
if isIncomplete {
|
||||||
statusCh = c.removeIncompleteObjects(bucket, objectsCh)
|
statusCh = c.removeIncompleteObjects(ctx, bucket, objectsCh)
|
||||||
} else {
|
} else {
|
||||||
statusCh = c.api.RemoveObjectsWithOptions(bucket, objectsCh, opts)
|
statusCh = c.api.RemoveObjectsWithOptionsContext(ctx, bucket, objectsCh, opts)
|
||||||
}
|
}
|
||||||
prevBucket = bucket
|
prevBucket = bucket
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1163,7 @@ func (c *S3Client) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh
|
|||||||
}
|
}
|
||||||
// Remove last bucket if it qualifies.
|
// Remove last bucket if it qualifies.
|
||||||
if isRemoveBucket && prevBucket != "" && !isIncomplete {
|
if isRemoveBucket && prevBucket != "" && !isIncomplete {
|
||||||
if err := c.api.RemoveBucket(prevBucket); err != nil {
|
if err := c.api.RemoveBucketWithContext(ctx, prevBucket); err != nil {
|
||||||
errorCh <- probe.NewError(err)
|
errorCh <- probe.NewError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1165,7 +1172,7 @@ func (c *S3Client) Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeBucket - make a new bucket.
|
// MakeBucket - make a new bucket.
|
||||||
func (c *S3Client) MakeBucket(region string, ignoreExisting, withLock bool) *probe.Error {
|
func (c *S3Client) MakeBucket(ctx context.Context, region string, ignoreExisting, withLock bool) *probe.Error {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
@@ -1179,7 +1186,7 @@ func (c *S3Client) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
|||||||
}
|
}
|
||||||
var retried bool
|
var retried bool
|
||||||
for {
|
for {
|
||||||
_, e := c.api.PutObject(bucket, object,
|
_, e := c.api.PutObjectWithContext(ctx, bucket, object,
|
||||||
bytes.NewReader([]byte("")), 0, minio.PutObjectOptions{})
|
bytes.NewReader([]byte("")), 0, minio.PutObjectOptions{})
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -1190,9 +1197,9 @@ func (c *S3Client) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
|||||||
switch minio.ToErrorResponse(e).Code {
|
switch minio.ToErrorResponse(e).Code {
|
||||||
case "NoSuchBucket":
|
case "NoSuchBucket":
|
||||||
if withLock {
|
if withLock {
|
||||||
e = c.api.MakeBucketWithObjectLock(bucket, region)
|
e = c.api.MakeBucketWithObjectLockWithContext(ctx, bucket, region)
|
||||||
} else {
|
} else {
|
||||||
e = c.api.MakeBucket(bucket, region)
|
e = c.api.MakeBucketWithContext(ctx, bucket, region)
|
||||||
}
|
}
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
@@ -1206,9 +1213,9 @@ func (c *S3Client) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
|||||||
|
|
||||||
var e error
|
var e error
|
||||||
if withLock {
|
if withLock {
|
||||||
e = c.api.MakeBucketWithObjectLock(bucket, region)
|
e = c.api.MakeBucketWithObjectLockWithContext(ctx, bucket, region)
|
||||||
} else {
|
} else {
|
||||||
e = c.api.MakeBucket(bucket, region)
|
e = c.api.MakeBucketWithContext(ctx, bucket, region)
|
||||||
}
|
}
|
||||||
if e != nil {
|
if e != nil {
|
||||||
// Ignore bucket already existing error when ignoreExisting flag is enabled
|
// Ignore bucket already existing error when ignoreExisting flag is enabled
|
||||||
@@ -1226,13 +1233,13 @@ func (c *S3Client) MakeBucket(region string, ignoreExisting, withLock bool) *pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessRules - get configured policies from the server
|
// GetAccessRules - get configured policies from the server
|
||||||
func (c *S3Client) GetAccessRules() (map[string]string, *probe.Error) {
|
func (c *S3Client) GetAccessRules(ctx context.Context) (map[string]string, *probe.Error) {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return map[string]string{}, probe.NewError(BucketNameEmpty{})
|
return map[string]string{}, probe.NewError(BucketNameEmpty{})
|
||||||
}
|
}
|
||||||
policies := map[string]string{}
|
policies := map[string]string{}
|
||||||
policyStr, e := c.api.GetBucketPolicy(bucket)
|
policyStr, e := c.api.GetBucketPolicyWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, probe.NewError(e)
|
return nil, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -1252,12 +1259,12 @@ func (c *S3Client) GetAccessRules() (map[string]string, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccess get access policy permissions.
|
// GetAccess get access policy permissions.
|
||||||
func (c *S3Client) GetAccess() (string, string, *probe.Error) {
|
func (c *S3Client) GetAccess(ctx context.Context) (string, string, *probe.Error) {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return "", "", probe.NewError(BucketNameEmpty{})
|
return "", "", probe.NewError(BucketNameEmpty{})
|
||||||
}
|
}
|
||||||
policyStr, e := c.api.GetBucketPolicy(bucket)
|
policyStr, e := c.api.GetBucketPolicyWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", "", probe.NewError(e)
|
return "", "", probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -1276,18 +1283,18 @@ func (c *S3Client) GetAccess() (string, string, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAccess set access policy permissions.
|
// SetAccess set access policy permissions.
|
||||||
func (c *S3Client) SetAccess(bucketPolicy string, isJSON bool) *probe.Error {
|
func (c *S3Client) SetAccess(ctx context.Context, bucketPolicy string, isJSON bool) *probe.Error {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
}
|
}
|
||||||
if isJSON {
|
if isJSON {
|
||||||
if e := c.api.SetBucketPolicy(bucket, bucketPolicy); e != nil {
|
if e := c.api.SetBucketPolicyWithContext(ctx, bucket, bucketPolicy); e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
policyStr, e := c.api.GetBucketPolicy(bucket)
|
policyStr, e := c.api.GetBucketPolicyWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -1299,7 +1306,7 @@ func (c *S3Client) SetAccess(bucketPolicy string, isJSON bool) *probe.Error {
|
|||||||
}
|
}
|
||||||
p.Statements = policy.SetPolicy(p.Statements, policy.BucketPolicy(bucketPolicy), bucket, object)
|
p.Statements = policy.SetPolicy(p.Statements, policy.BucketPolicy(bucketPolicy), bucket, object)
|
||||||
if len(p.Statements) == 0 {
|
if len(p.Statements) == 0 {
|
||||||
if e = c.api.SetBucketPolicy(bucket, ""); e != nil {
|
if e = c.api.SetBucketPolicyWithContext(ctx, bucket, ""); e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -1308,32 +1315,32 @@ func (c *S3Client) SetAccess(bucketPolicy string, isJSON bool) *probe.Error {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
if e = c.api.SetBucketPolicy(bucket, string(policyB)); e != nil {
|
if e = c.api.SetBucketPolicyWithContext(ctx, bucket, string(policyB)); e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// listObjectWrapper - select ObjectList version depending on the target hostname
|
// listObjectWrapper - select ObjectList version depending on the target hostname
|
||||||
func (c *S3Client) listObjectWrapper(bucket, object string, isRecursive bool, doneCh chan struct{}, metadata bool) <-chan minio.ObjectInfo {
|
func (c *S3Client) listObjectWrapper(ctx context.Context, bucket, object string, isRecursive bool, doneCh chan struct{}, metadata bool) <-chan minio.ObjectInfo {
|
||||||
if isGoogle(c.targetURL.Host) {
|
if isGoogle(c.targetURL.Host) {
|
||||||
// Google Cloud S3 layer doesn't implement ListObjectsV2 implementation
|
// Google Cloud S3 layer doesn't implement ListObjectsV2 implementation
|
||||||
// https://github.com/minio/mc/issues/3073
|
// https://github.com/minio/mc/issues/3073
|
||||||
return c.api.ListObjects(bucket, object, isRecursive, doneCh)
|
return c.api.ListObjectsWithContext(ctx, bucket, object, isRecursive, doneCh)
|
||||||
}
|
}
|
||||||
if metadata {
|
if metadata {
|
||||||
return c.api.ListObjectsV2WithMetadata(bucket, object, isRecursive, doneCh)
|
return c.api.ListObjectsV2WithMetadataWithContext(ctx, bucket, object, isRecursive, doneCh)
|
||||||
}
|
}
|
||||||
return c.api.ListObjectsV2(bucket, object, isRecursive, doneCh)
|
return c.api.ListObjectsV2WithContext(ctx, bucket, object, isRecursive, doneCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Client) statIncompleteUpload(bucket, object string) (*ClientContent, *probe.Error) {
|
func (c *S3Client) statIncompleteUpload(ctx context.Context, bucket, object string) (*ClientContent, *probe.Error) {
|
||||||
nonRecursive := false
|
nonRecursive := false
|
||||||
objectMetadata := &ClientContent{}
|
objectMetadata := &ClientContent{}
|
||||||
// Prefix to pass to minio-go listing in order to fetch a given object/directory
|
// Prefix to pass to minio-go listing in order to fetch a given object/directory
|
||||||
prefix := strings.TrimRight(object, string(c.targetURL.Separator))
|
prefix := strings.TrimRight(object, string(c.targetURL.Separator))
|
||||||
|
|
||||||
for objectMultipartInfo := range c.api.ListIncompleteUploads(bucket, prefix, nonRecursive, nil) {
|
for objectMultipartInfo := range c.api.ListIncompleteUploadsWithContext(ctx, bucket, prefix, nonRecursive, nil) {
|
||||||
if objectMultipartInfo.Err != nil {
|
if objectMultipartInfo.Err != nil {
|
||||||
return nil, probe.NewError(objectMultipartInfo.Err)
|
return nil, probe.NewError(objectMultipartInfo.Err)
|
||||||
}
|
}
|
||||||
@@ -1359,7 +1366,7 @@ func (c *S3Client) statIncompleteUpload(bucket, object string) (*ClientContent,
|
|||||||
|
|
||||||
// Stat - send a 'HEAD' on a bucket or object to fetch its metadata. It also returns
|
// Stat - send a 'HEAD' on a bucket or object to fetch its metadata. It also returns
|
||||||
// a DIR type content if a prefix does exist in the server.
|
// a DIR type content if a prefix does exist in the server.
|
||||||
func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (*ClientContent, *probe.Error) {
|
func (c *S3Client) Stat(ctx context.Context, isIncomplete, isPreserve bool, sse encrypt.ServerSide) (*ClientContent, *probe.Error) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
@@ -1370,7 +1377,7 @@ func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if object == "" {
|
if object == "" {
|
||||||
content, err := c.bucketStat(bucket)
|
content, err := c.bucketStat(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(bucket)
|
return nil, err.Trace(bucket)
|
||||||
}
|
}
|
||||||
@@ -1379,7 +1386,7 @@ func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
|
|||||||
|
|
||||||
// If the request is for incomplete upload stat, handle it here.
|
// If the request is for incomplete upload stat, handle it here.
|
||||||
if isIncomplete {
|
if isIncomplete {
|
||||||
return c.statIncompleteUpload(bucket, object)
|
return c.statIncompleteUpload(ctx, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following code tries to calculate if a given prefix/object does really exist
|
// The following code tries to calculate if a given prefix/object does really exist
|
||||||
@@ -1396,7 +1403,7 @@ func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
|
|||||||
if !strings.HasSuffix(object, string(c.targetURL.Separator)) {
|
if !strings.HasSuffix(object, string(c.targetURL.Separator)) {
|
||||||
// Issue HEAD request first but ignore no such key error
|
// Issue HEAD request first but ignore no such key error
|
||||||
// so we can check if there is such prefix which exists
|
// so we can check if there is such prefix which exists
|
||||||
ctnt, err := c.getObjectStat(bucket, object, opts)
|
ctnt, err := c.getObjectStat(ctx, bucket, object, opts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ctnt, err
|
return ctnt, err
|
||||||
}
|
}
|
||||||
@@ -1412,7 +1419,7 @@ func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
|
|||||||
// Prefix to pass to minio-go listing in order to fetch if a prefix exists
|
// Prefix to pass to minio-go listing in order to fetch if a prefix exists
|
||||||
prefix := strings.TrimRight(object, string(c.targetURL.Separator))
|
prefix := strings.TrimRight(object, string(c.targetURL.Separator))
|
||||||
|
|
||||||
for objectStat := range c.listObjectWrapper(bucket, prefix, nonRecursive, nil, false) {
|
for objectStat := range c.listObjectWrapper(ctx, bucket, prefix, nonRecursive, nil, false) {
|
||||||
if objectStat.Err != nil {
|
if objectStat.Err != nil {
|
||||||
return nil, probe.NewError(objectStat.Err)
|
return nil, probe.NewError(objectStat.Err)
|
||||||
}
|
}
|
||||||
@@ -1427,8 +1434,8 @@ func (c *S3Client) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getObjectStat returns the metadata of an object from a HEAD call.
|
// getObjectStat returns the metadata of an object from a HEAD call.
|
||||||
func (c *S3Client) getObjectStat(bucket, object string, opts minio.StatObjectOptions) (*ClientContent, *probe.Error) {
|
func (c *S3Client) getObjectStat(ctx context.Context, bucket, object string, opts minio.StatObjectOptions) (*ClientContent, *probe.Error) {
|
||||||
objectStat, e := c.api.StatObject(bucket, object, opts)
|
objectStat, e := c.api.StatObjectWithContext(ctx, bucket, object, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
errResponse := minio.ToErrorResponse(e)
|
errResponse := minio.ToErrorResponse(e)
|
||||||
if errResponse.Code == "AccessDenied" {
|
if errResponse.Code == "AccessDenied" {
|
||||||
@@ -1542,7 +1549,7 @@ func (c *S3Client) splitPath(path string) (bucketName, objectName string) {
|
|||||||
/// Bucket API operations.
|
/// Bucket API operations.
|
||||||
|
|
||||||
// List - list at delimited path, if not recursive.
|
// List - list at delimited path, if not recursive.
|
||||||
func (c *S3Client) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent {
|
func (c *S3Client) List(ctx context.Context, isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
@@ -1550,35 +1557,35 @@ func (c *S3Client) List(isRecursive, isIncomplete, isMetadata bool, showDir DirO
|
|||||||
if isIncomplete {
|
if isIncomplete {
|
||||||
if isRecursive {
|
if isRecursive {
|
||||||
if showDir == DirNone {
|
if showDir == DirNone {
|
||||||
go c.listIncompleteRecursiveInRoutine(contentCh)
|
go c.listIncompleteRecursiveInRoutine(ctx, contentCh)
|
||||||
} else {
|
} else {
|
||||||
go c.listIncompleteRecursiveInRoutineDirOpt(contentCh, showDir)
|
go c.listIncompleteRecursiveInRoutineDirOpt(ctx, contentCh, showDir)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
go c.listIncompleteInRoutine(contentCh)
|
go c.listIncompleteInRoutine(ctx, contentCh)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if isRecursive {
|
if isRecursive {
|
||||||
if showDir == DirNone {
|
if showDir == DirNone {
|
||||||
go c.listRecursiveInRoutine(contentCh, isMetadata)
|
go c.listRecursiveInRoutine(ctx, contentCh, isMetadata)
|
||||||
} else {
|
} else {
|
||||||
go c.listRecursiveInRoutineDirOpt(contentCh, showDir, isMetadata)
|
go c.listRecursiveInRoutineDirOpt(ctx, contentCh, showDir, isMetadata)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
go c.listInRoutine(contentCh, isMetadata)
|
go c.listInRoutine(ctx, contentCh, isMetadata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentCh
|
return contentCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Client) listIncompleteInRoutine(contentCh chan *ClientContent) {
|
func (c *S3Client) listIncompleteInRoutine(ctx context.Context, contentCh chan *ClientContent) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
// get bucket and object from URL.
|
// get bucket and object from URL.
|
||||||
b, o := c.url2BucketAndObject()
|
b, o := c.url2BucketAndObject()
|
||||||
switch {
|
switch {
|
||||||
case b == "" && o == "":
|
case b == "" && o == "":
|
||||||
buckets, err := c.api.ListBuckets()
|
buckets, err := c.api.ListBucketsWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(err),
|
Err: probe.NewError(err),
|
||||||
@@ -1587,7 +1594,7 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *ClientContent) {
|
|||||||
}
|
}
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
for object := range c.api.ListIncompleteUploads(bucket.Name, o, isRecursive, nil) {
|
for object := range c.api.ListIncompleteUploadsWithContext(ctx, bucket.Name, o, isRecursive, nil) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -1615,7 +1622,7 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *ClientContent) {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
for object := range c.api.ListIncompleteUploads(b, o, isRecursive, nil) {
|
for object := range c.api.ListIncompleteUploadsWithContext(ctx, b, o, isRecursive, nil) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -1643,13 +1650,13 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *ClientContent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *ClientContent) {
|
func (c *S3Client) listIncompleteRecursiveInRoutine(ctx context.Context, contentCh chan *ClientContent) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
// get bucket and object from URL.
|
// get bucket and object from URL.
|
||||||
b, o := c.url2BucketAndObject()
|
b, o := c.url2BucketAndObject()
|
||||||
switch {
|
switch {
|
||||||
case b == "" && o == "":
|
case b == "" && o == "":
|
||||||
buckets, err := c.api.ListBuckets()
|
buckets, err := c.api.ListBucketsWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(err),
|
Err: probe.NewError(err),
|
||||||
@@ -1658,7 +1665,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *ClientConten
|
|||||||
}
|
}
|
||||||
isRecursive := true
|
isRecursive := true
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
for object := range c.api.ListIncompleteUploads(bucket.Name, o, isRecursive, nil) {
|
for object := range c.api.ListIncompleteUploadsWithContext(ctx, bucket.Name, o, isRecursive, nil) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -1677,7 +1684,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *ClientConten
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
isRecursive := true
|
isRecursive := true
|
||||||
for object := range c.api.ListIncompleteUploads(b, o, isRecursive, nil) {
|
for object := range c.api.ListIncompleteUploadsWithContext(ctx, b, o, isRecursive, nil) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -1718,7 +1725,7 @@ func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recursively lists incomplete uploads.
|
// Recursively lists incomplete uploads.
|
||||||
func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *ClientContent, dirOpt DirOpt) {
|
func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(ctx context.Context, contentCh chan *ClientContent, dirOpt DirOpt) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
|
|
||||||
// Closure function reads list of incomplete uploads and sends to contentCh. If a directory is found, it lists
|
// Closure function reads list of incomplete uploads and sends to contentCh. If a directory is found, it lists
|
||||||
@@ -1726,7 +1733,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *Client
|
|||||||
var listDir func(bucket, object string) bool
|
var listDir func(bucket, object string) bool
|
||||||
listDir = func(bucket, object string) (isStop bool) {
|
listDir = func(bucket, object string) (isStop bool) {
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
for entry := range c.api.ListIncompleteUploads(bucket, object, isRecursive, nil) {
|
for entry := range c.api.ListIncompleteUploadsWithContext(ctx, bucket, object, isRecursive, nil) {
|
||||||
if entry.Err != nil {
|
if entry.Err != nil {
|
||||||
url := c.targetURL.Clone()
|
url := c.targetURL.Clone()
|
||||||
url.Path = c.joinPath(bucket, object)
|
url.Path = c.joinPath(bucket, object)
|
||||||
@@ -1769,14 +1776,14 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *Client
|
|||||||
if bucket == "" && object == "" {
|
if bucket == "" && object == "" {
|
||||||
var e error
|
var e error
|
||||||
allBuckets = true
|
allBuckets = true
|
||||||
buckets, e = c.api.ListBuckets()
|
buckets, e = c.api.ListBucketsWithContext(ctx)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
contentCh <- &ClientContent{Err: probe.NewError(e)}
|
contentCh <- &ClientContent{Err: probe.NewError(e)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if object == "" {
|
} else if object == "" {
|
||||||
// Get bucket stat if object is empty.
|
// Get bucket stat if object is empty.
|
||||||
content, err := c.bucketStat(bucket)
|
content, err := c.bucketStat(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{Err: err.Trace(bucket)}
|
contentCh <- &ClientContent{Err: err.Trace(bucket)}
|
||||||
return
|
return
|
||||||
@@ -1785,7 +1792,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *Client
|
|||||||
} else if strings.HasSuffix(object, string(c.targetURL.Separator)) {
|
} else if strings.HasSuffix(object, string(c.targetURL.Separator)) {
|
||||||
// Get stat of given object is a directory.
|
// Get stat of given object is a directory.
|
||||||
isIncomplete := true
|
isIncomplete := true
|
||||||
content, perr := c.Stat(isIncomplete, false, nil)
|
content, perr := c.Stat(ctx, isIncomplete, false, nil)
|
||||||
cContent = content
|
cContent = content
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
contentCh <- &ClientContent{Err: perr.Trace(bucket)}
|
contentCh <- &ClientContent{Err: perr.Trace(bucket)}
|
||||||
@@ -1866,8 +1873,8 @@ func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns bucket stat info of current bucket.
|
// Returns bucket stat info of current bucket.
|
||||||
func (c *S3Client) bucketStat(bucket string) (*ClientContent, *probe.Error) {
|
func (c *S3Client) bucketStat(ctx context.Context, bucket string) (*ClientContent, *probe.Error) {
|
||||||
exists, e := c.api.BucketExists(bucket)
|
exists, e := c.api.BucketExistsWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, probe.NewError(e)
|
return nil, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -1878,14 +1885,14 @@ func (c *S3Client) bucketStat(bucket string) (*ClientContent, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recursively lists objects.
|
// Recursively lists objects.
|
||||||
func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *ClientContent, dirOpt DirOpt, metadata bool) {
|
func (c *S3Client) listRecursiveInRoutineDirOpt(ctx context.Context, contentCh chan *ClientContent, dirOpt DirOpt, metadata bool) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
// Closure function reads list objects and sends to contentCh. If a directory is found, it lists
|
// Closure function reads list objects and sends to contentCh. If a directory is found, it lists
|
||||||
// objects of the directory content recursively.
|
// objects of the directory content recursively.
|
||||||
var listDir func(bucket, object string) bool
|
var listDir func(bucket, object string) bool
|
||||||
listDir = func(bucket, object string) (isStop bool) {
|
listDir = func(bucket, object string) (isStop bool) {
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
for entry := range c.listObjectWrapper(bucket, object, isRecursive, nil, metadata) {
|
for entry := range c.listObjectWrapper(ctx, bucket, object, isRecursive, nil, metadata) {
|
||||||
if entry.Err != nil {
|
if entry.Err != nil {
|
||||||
url := c.targetURL.Clone()
|
url := c.targetURL.Clone()
|
||||||
url.Path = c.joinPath(bucket, object)
|
url.Path = c.joinPath(bucket, object)
|
||||||
@@ -1927,14 +1934,14 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *ClientContent, d
|
|||||||
if bucket == "" && object == "" {
|
if bucket == "" && object == "" {
|
||||||
var e error
|
var e error
|
||||||
allBuckets = true
|
allBuckets = true
|
||||||
buckets, e = c.api.ListBuckets()
|
buckets, e = c.api.ListBucketsWithContext(ctx)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
contentCh <- &ClientContent{Err: probe.NewError(e)}
|
contentCh <- &ClientContent{Err: probe.NewError(e)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if object == "" {
|
} else if object == "" {
|
||||||
// Get bucket stat if object is empty.
|
// Get bucket stat if object is empty.
|
||||||
content, err := c.bucketStat(bucket)
|
content, err := c.bucketStat(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{Err: err.Trace(bucket)}
|
contentCh <- &ClientContent{Err: err.Trace(bucket)}
|
||||||
return
|
return
|
||||||
@@ -1943,7 +1950,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *ClientContent, d
|
|||||||
} else {
|
} else {
|
||||||
// Get stat of given object is a directory.
|
// Get stat of given object is a directory.
|
||||||
isIncomplete := false
|
isIncomplete := false
|
||||||
content, perr := c.Stat(isIncomplete, false, nil)
|
content, perr := c.Stat(ctx, isIncomplete, false, nil)
|
||||||
cContent = content
|
cContent = content
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
contentCh <- &ClientContent{Err: perr.Trace(bucket)}
|
contentCh <- &ClientContent{Err: perr.Trace(bucket)}
|
||||||
@@ -1968,13 +1975,13 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *ClientContent, d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Client) listInRoutine(contentCh chan *ClientContent, metadata bool) {
|
func (c *S3Client) listInRoutine(ctx context.Context, contentCh chan *ClientContent, metadata bool) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
// get bucket and object from URL.
|
// get bucket and object from URL.
|
||||||
b, o := c.url2BucketAndObject()
|
b, o := c.url2BucketAndObject()
|
||||||
switch {
|
switch {
|
||||||
case b == "" && o == "":
|
case b == "" && o == "":
|
||||||
buckets, e := c.api.ListBuckets()
|
buckets, e := c.api.ListBucketsWithContext(ctx)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(e),
|
Err: probe.NewError(e),
|
||||||
@@ -1985,7 +1992,7 @@ func (c *S3Client) listInRoutine(contentCh chan *ClientContent, metadata bool) {
|
|||||||
contentCh <- c.bucketInfo2ClientContent(bucket)
|
contentCh <- c.bucketInfo2ClientContent(bucket)
|
||||||
}
|
}
|
||||||
case b != "" && !strings.HasSuffix(c.targetURL.Path, string(c.targetURL.Separator)) && o == "":
|
case b != "" && !strings.HasSuffix(c.targetURL.Path, string(c.targetURL.Separator)) && o == "":
|
||||||
content, err := c.bucketStat(b)
|
content, err := c.bucketStat(ctx, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{Err: err.Trace(b)}
|
contentCh <- &ClientContent{Err: err.Trace(b)}
|
||||||
return
|
return
|
||||||
@@ -1993,7 +2000,7 @@ func (c *S3Client) listInRoutine(contentCh chan *ClientContent, metadata bool) {
|
|||||||
contentCh <- content
|
contentCh <- content
|
||||||
default:
|
default:
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
for object := range c.listObjectWrapper(b, o, isRecursive, nil, metadata) {
|
for object := range c.listObjectWrapper(ctx, b, o, isRecursive, nil, metadata) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -2024,13 +2031,13 @@ const (
|
|||||||
s3StorageClassGlacier = "GLACIER"
|
s3StorageClassGlacier = "GLACIER"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *S3Client) listRecursiveInRoutine(contentCh chan *ClientContent, metadata bool) {
|
func (c *S3Client) listRecursiveInRoutine(ctx context.Context, contentCh chan *ClientContent, metadata bool) {
|
||||||
defer close(contentCh)
|
defer close(contentCh)
|
||||||
// get bucket and object from URL.
|
// get bucket and object from URL.
|
||||||
b, o := c.url2BucketAndObject()
|
b, o := c.url2BucketAndObject()
|
||||||
switch {
|
switch {
|
||||||
case b == "" && o == "":
|
case b == "" && o == "":
|
||||||
buckets, err := c.api.ListBuckets()
|
buckets, err := c.api.ListBucketsWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(err),
|
Err: probe.NewError(err),
|
||||||
@@ -2039,7 +2046,7 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *ClientContent, metadat
|
|||||||
}
|
}
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
isRecursive := true
|
isRecursive := true
|
||||||
for object := range c.listObjectWrapper(bucket.Name, o, isRecursive, nil, metadata) {
|
for object := range c.listObjectWrapper(ctx, bucket.Name, o, isRecursive, nil, metadata) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -2051,7 +2058,7 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *ClientContent, metadat
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
isRecursive := true
|
isRecursive := true
|
||||||
for object := range c.listObjectWrapper(b, o, isRecursive, nil, metadata) {
|
for object := range c.listObjectWrapper(ctx, b, o, isRecursive, nil, metadata) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
contentCh <- &ClientContent{
|
contentCh <- &ClientContent{
|
||||||
Err: probe.NewError(object.Err),
|
Err: probe.NewError(object.Err),
|
||||||
@@ -2064,11 +2071,11 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *ClientContent, metadat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ShareDownload - get a usable presigned object url to share.
|
// ShareDownload - get a usable presigned object url to share.
|
||||||
func (c *S3Client) ShareDownload(expires time.Duration) (string, *probe.Error) {
|
func (c *S3Client) ShareDownload(ctx context.Context, expires time.Duration) (string, *probe.Error) {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
// No additional request parameters are set for the time being.
|
// No additional request parameters are set for the time being.
|
||||||
reqParams := make(url.Values)
|
reqParams := make(url.Values)
|
||||||
presignedURL, e := c.api.PresignedGetObject(bucket, object, expires, reqParams)
|
presignedURL, e := c.api.PresignedGetObjectWithContext(ctx, bucket, object, expires, reqParams)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", probe.NewError(e)
|
return "", probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -2106,20 +2113,20 @@ func (c *S3Client) ShareUpload(isRecursive bool, expires time.Duration, contentT
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetObjectLockConfig - Set object lock configurataion of bucket.
|
// SetObjectLockConfig - Set object lock configurataion of bucket.
|
||||||
func (c *S3Client) SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
func (c *S3Client) SetObjectLockConfig(ctx context.Context, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
|
|
||||||
// FIXME: This is too ugly, fix minio-go
|
// FIXME: This is too ugly, fix minio-go
|
||||||
vuint := (uint)(validity)
|
vuint := (uint)(validity)
|
||||||
if mode != "" && vuint > 0 && unit != "" {
|
if mode != "" && vuint > 0 && unit != "" {
|
||||||
e := c.api.SetBucketObjectLockConfig(bucket, &mode, &vuint, &unit)
|
e := c.api.SetBucketObjectLockConfigWithContext(ctx, bucket, &mode, &vuint, &unit)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e).Trace(c.GetURL().String())
|
return probe.NewError(e).Trace(c.GetURL().String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if mode == "" && vuint == 0 && unit == "" {
|
if mode == "" && vuint == 0 && unit == "" {
|
||||||
e := c.api.SetBucketObjectLockConfig(bucket, nil, nil, nil)
|
e := c.api.SetBucketObjectLockConfigWithContext(ctx, bucket, nil, nil, nil)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e).Trace(c.GetURL().String())
|
return probe.NewError(e).Trace(c.GetURL().String())
|
||||||
}
|
}
|
||||||
@@ -2129,7 +2136,7 @@ func (c *S3Client) SetObjectLockConfig(mode minio.RetentionMode, validity uint64
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PutObjectRetention - Set object retention for a given object.
|
// PutObjectRetention - Set object retention for a given object.
|
||||||
func (c *S3Client) PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
func (c *S3Client) PutObjectRetention(ctx context.Context, mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
|
|
||||||
if mode != "" && !retainUntilDate.IsZero() {
|
if mode != "" && !retainUntilDate.IsZero() {
|
||||||
@@ -2138,7 +2145,7 @@ func (c *S3Client) PutObjectRetention(mode minio.RetentionMode, retainUntilDate
|
|||||||
Mode: &mode,
|
Mode: &mode,
|
||||||
GovernanceBypass: bypassGovernance,
|
GovernanceBypass: bypassGovernance,
|
||||||
}
|
}
|
||||||
e := c.api.PutObjectRetention(bucket, object, opts)
|
e := c.api.PutObjectRetentionWithContext(ctx, bucket, object, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e).Trace(c.GetURL().String())
|
return probe.NewError(e).Trace(c.GetURL().String())
|
||||||
}
|
}
|
||||||
@@ -2149,13 +2156,13 @@ func (c *S3Client) PutObjectRetention(mode minio.RetentionMode, retainUntilDate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PutObjectLegalHold - Set object legal hold for a given object.
|
// PutObjectLegalHold - Set object legal hold for a given object.
|
||||||
func (c *S3Client) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error {
|
func (c *S3Client) PutObjectLegalHold(ctx context.Context, lhold minio.LegalHoldStatus) *probe.Error {
|
||||||
bucket, object := c.url2BucketAndObject()
|
bucket, object := c.url2BucketAndObject()
|
||||||
if lhold.IsValid() {
|
if lhold.IsValid() {
|
||||||
opts := minio.PutObjectLegalHoldOptions{
|
opts := minio.PutObjectLegalHoldOptions{
|
||||||
Status: &lhold,
|
Status: &lhold,
|
||||||
}
|
}
|
||||||
e := c.api.PutObjectLegalHold(bucket, object, opts)
|
e := c.api.PutObjectLegalHoldWithContext(ctx, bucket, object, opts)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return probe.NewError(e).Trace(c.GetURL().String())
|
return probe.NewError(e).Trace(c.GetURL().String())
|
||||||
}
|
}
|
||||||
@@ -2165,10 +2172,10 @@ func (c *S3Client) PutObjectLegalHold(lhold minio.LegalHoldStatus) *probe.Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetObjectLockConfig - Get object lock configuration of bucket.
|
// GetObjectLockConfig - Get object lock configuration of bucket.
|
||||||
func (c *S3Client) GetObjectLockConfig() (minio.RetentionMode, uint64, minio.ValidityUnit, *probe.Error) {
|
func (c *S3Client) GetObjectLockConfig(ctx context.Context) (minio.RetentionMode, uint64, minio.ValidityUnit, *probe.Error) {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
|
|
||||||
mode, validity, unit, e := c.api.GetBucketObjectLockConfig(bucket)
|
mode, validity, unit, e := c.api.GetBucketObjectLockConfigWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", 0, "", probe.NewError(e).Trace(c.GetURL().String())
|
return "", 0, "", probe.NewError(e).Trace(c.GetURL().String())
|
||||||
}
|
}
|
||||||
@@ -2183,14 +2190,14 @@ func (c *S3Client) GetObjectLockConfig() (minio.RetentionMode, uint64, minio.Val
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTags - Get tags of bucket or object.
|
// GetTags - Get tags of bucket or object.
|
||||||
func (c *S3Client) GetTags() (*tags.Tags, *probe.Error) {
|
func (c *S3Client) GetTags(ctx context.Context) (*tags.Tags, *probe.Error) {
|
||||||
bucketName, objectName := c.url2BucketAndObject()
|
bucketName, objectName := c.url2BucketAndObject()
|
||||||
if bucketName == "" {
|
if bucketName == "" {
|
||||||
return nil, probe.NewError(BucketNameEmpty{})
|
return nil, probe.NewError(BucketNameEmpty{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if objectName == "" {
|
if objectName == "" {
|
||||||
tags, err := c.api.GetBucketTagging(bucketName)
|
tags, err := c.api.GetBucketTaggingWithContext(ctx, bucketName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, probe.NewError(err)
|
return nil, probe.NewError(err)
|
||||||
}
|
}
|
||||||
@@ -2198,7 +2205,7 @@ func (c *S3Client) GetTags() (*tags.Tags, *probe.Error) {
|
|||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := c.api.GetObjectTagging(bucketName, objectName)
|
s, err := c.api.GetObjectTaggingWithContext(ctx, bucketName, objectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, probe.NewError(err)
|
return nil, probe.NewError(err)
|
||||||
}
|
}
|
||||||
@@ -2212,7 +2219,7 @@ func (c *S3Client) GetTags() (*tags.Tags, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetTags - Set tags of bucket or object.
|
// SetTags - Set tags of bucket or object.
|
||||||
func (c *S3Client) SetTags(tagString string) *probe.Error {
|
func (c *S3Client) SetTags(ctx context.Context, tagString string) *probe.Error {
|
||||||
bucketName, objectName := c.url2BucketAndObject()
|
bucketName, objectName := c.url2BucketAndObject()
|
||||||
if bucketName == "" {
|
if bucketName == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
@@ -2224,9 +2231,9 @@ func (c *S3Client) SetTags(tagString string) *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if objectName == "" {
|
if objectName == "" {
|
||||||
err = c.api.SetBucketTagging(bucketName, tags)
|
err = c.api.SetBucketTaggingWithContext(ctx, bucketName, tags)
|
||||||
} else {
|
} else {
|
||||||
err = c.api.PutObjectTagging(bucketName, objectName, tags.ToMap())
|
err = c.api.PutObjectTaggingWithContext(ctx, bucketName, objectName, tags.ToMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2237,7 +2244,7 @@ func (c *S3Client) SetTags(tagString string) *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTags - Delete tags of bucket or object
|
// DeleteTags - Delete tags of bucket or object
|
||||||
func (c *S3Client) DeleteTags() *probe.Error {
|
func (c *S3Client) DeleteTags(ctx context.Context) *probe.Error {
|
||||||
bucketName, objectName := c.url2BucketAndObject()
|
bucketName, objectName := c.url2BucketAndObject()
|
||||||
if bucketName == "" {
|
if bucketName == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
@@ -2245,9 +2252,9 @@ func (c *S3Client) DeleteTags() *probe.Error {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
if objectName == "" {
|
if objectName == "" {
|
||||||
err = c.api.DeleteBucketTagging(bucketName)
|
err = c.api.DeleteBucketTaggingWithContext(ctx, bucketName)
|
||||||
} else {
|
} else {
|
||||||
err = c.api.RemoveObjectTagging(bucketName, objectName)
|
err = c.api.RemoveObjectTaggingWithContext(ctx, bucketName, objectName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2258,13 +2265,13 @@ func (c *S3Client) DeleteTags() *probe.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLifecycle - Get current lifecycle configuration.
|
// GetLifecycle - Get current lifecycle configuration.
|
||||||
func (c *S3Client) GetLifecycle() (ilm.LifecycleConfiguration, *probe.Error) {
|
func (c *S3Client) GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error) {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return ilm.LifecycleConfiguration{}, probe.NewError(BucketNameEmpty{})
|
return ilm.LifecycleConfiguration{}, probe.NewError(BucketNameEmpty{})
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleXML, e := c.api.GetBucketLifecycle(bucket)
|
lifecycleXML, e := c.api.GetBucketLifecycleWithContext(ctx, bucket)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return ilm.LifecycleConfiguration{}, probe.NewError(e)
|
return ilm.LifecycleConfiguration{}, probe.NewError(e)
|
||||||
}
|
}
|
||||||
@@ -2278,7 +2285,7 @@ func (c *S3Client) GetLifecycle() (ilm.LifecycleConfiguration, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetLifecycle - Set lifecycle configuration on a bucket
|
// SetLifecycle - Set lifecycle configuration on a bucket
|
||||||
func (c *S3Client) SetLifecycle(ilmCfg ilm.LifecycleConfiguration) *probe.Error {
|
func (c *S3Client) SetLifecycle(ctx context.Context, ilmCfg ilm.LifecycleConfiguration) *probe.Error {
|
||||||
bucket, _ := c.url2BucketAndObject()
|
bucket, _ := c.url2BucketAndObject()
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return probe.NewError(BucketNameEmpty{})
|
return probe.NewError(BucketNameEmpty{})
|
||||||
@@ -2293,7 +2300,7 @@ func (c *S3Client) SetLifecycle(ilmCfg ilm.LifecycleConfiguration) *probe.Error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e := c.api.SetBucketLifecycle(bucket, string(lifecycleXML)); e != nil {
|
if e := c.api.SetBucketLifecycleWithContext(ctx, bucket, string(lifecycleXML)); e != nil {
|
||||||
return probe.NewError(e)
|
return probe.NewError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,14 +171,14 @@ func (s *TestSuite) TestBucketOperations(c *C) {
|
|||||||
s3c, err := S3New(conf)
|
s3c, err := S3New(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
err = s3c.MakeBucket("us-east-1", true, false)
|
err = s3c.MakeBucket(context.Background(), "us-east-1", true, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
conf.HostURL = server.URL + string(s3c.GetURL().Separator)
|
conf.HostURL = server.URL + string(s3c.GetURL().Separator)
|
||||||
s3c, err = S3New(conf)
|
s3c, err = S3New(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
for content := range s3c.List(false, false, false, DirNone) {
|
for content := range s3c.List(globalContext, false, false, false, DirNone) {
|
||||||
c.Assert(content.Err, IsNil)
|
c.Assert(content.Err, IsNil)
|
||||||
c.Assert(content.Type.IsDir(), Equals, true)
|
c.Assert(content.Type.IsDir(), Equals, true)
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ func (s *TestSuite) TestBucketOperations(c *C) {
|
|||||||
s3c, err = S3New(conf)
|
s3c, err = S3New(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
for content := range s3c.List(false, false, false, DirNone) {
|
for content := range s3c.List(globalContext, false, false, false, DirNone) {
|
||||||
c.Assert(content.Err, IsNil)
|
c.Assert(content.Err, IsNil)
|
||||||
c.Assert(content.Type.IsDir(), Equals, true)
|
c.Assert(content.Type.IsDir(), Equals, true)
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ func (s *TestSuite) TestBucketOperations(c *C) {
|
|||||||
s3c, err = S3New(conf)
|
s3c, err = S3New(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
for content := range s3c.List(false, false, false, DirNone) {
|
for content := range s3c.List(globalContext, false, false, false, DirNone) {
|
||||||
c.Assert(content.Err, IsNil)
|
c.Assert(content.Err, IsNil)
|
||||||
c.Assert(content.Type.IsRegular(), Equals, true)
|
c.Assert(content.Type.IsRegular(), Equals, true)
|
||||||
}
|
}
|
||||||
@@ -223,11 +223,11 @@ func (s *TestSuite) TestObjectOperations(c *C) {
|
|||||||
reader = bytes.NewReader(object.data)
|
reader = bytes.NewReader(object.data)
|
||||||
n, err := s3c.Put(context.Background(), reader, int64(len(object.data)), map[string]string{
|
n, err := s3c.Put(context.Background(), reader, int64(len(object.data)), map[string]string{
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}, nil, nil, false, false)
|
}, nil, nil, false, false, false)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(n, Equals, int64(len(object.data)))
|
c.Assert(n, Equals, int64(len(object.data)))
|
||||||
|
|
||||||
reader, err = s3c.Get(nil)
|
reader, err = s3c.Get(context.Background(), nil)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-3
@@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -183,7 +184,7 @@ func urlJoinPath(url1, url2 string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// url2Stat returns stat info for URL.
|
// url2Stat returns stat info for URL.
|
||||||
func url2Stat(urlStr string, fileAttr bool, encKeyDB map[string][]prefixSSEPair) (client Client, content *ClientContent, err *probe.Error) {
|
func url2Stat(ctx context.Context, urlStr string, fileAttr bool, encKeyDB map[string][]prefixSSEPair) (client Client, content *ClientContent, err *probe.Error) {
|
||||||
client, err = newClient(urlStr)
|
client, err = newClient(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(urlStr)
|
return nil, nil, err.Trace(urlStr)
|
||||||
@@ -191,7 +192,7 @@ func url2Stat(urlStr string, fileAttr bool, encKeyDB map[string][]prefixSSEPair)
|
|||||||
alias, _ := url2Alias(urlStr)
|
alias, _ := url2Alias(urlStr)
|
||||||
sse := getSSE(urlStr, encKeyDB[alias])
|
sse := getSSE(urlStr, encKeyDB[alias])
|
||||||
|
|
||||||
content, err = client.Stat(false, fileAttr, sse)
|
content, err = client.Stat(ctx, false, fileAttr, sse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(urlStr)
|
return nil, nil, err.Trace(urlStr)
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ func isURLPrefixExists(urlPrefix string, incomplete bool) bool {
|
|||||||
isRecursive := false
|
isRecursive := false
|
||||||
isIncomplete := incomplete
|
isIncomplete := incomplete
|
||||||
isFetchMeta := false
|
isFetchMeta := false
|
||||||
for entry := range clnt.List(isRecursive, isIncomplete, isFetchMeta, DirNone) {
|
for entry := range clnt.List(globalContext, isRecursive, isIncomplete, isFetchMeta, DirNone) {
|
||||||
return entry.Err == nil
|
return entry.Err == nil
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
+22
-22
@@ -47,56 +47,56 @@ const defaultMultipartThreadsNum = 4
|
|||||||
// Client - client interface
|
// Client - client interface
|
||||||
type Client interface {
|
type Client interface {
|
||||||
// Common operations
|
// Common operations
|
||||||
Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error)
|
Stat(ctx context.Context, isIncomplete, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error)
|
||||||
List(isRecursive, isIncomplete, isFetchMeta bool, showDir DirOpt) <-chan *ClientContent
|
List(ctx context.Context, isRecursive, isIncomplete, isFetchMeta bool, showDir DirOpt) <-chan *ClientContent
|
||||||
|
|
||||||
// Bucket operations
|
// Bucket operations
|
||||||
MakeBucket(region string, ignoreExisting, withLock bool) *probe.Error
|
MakeBucket(ctx context.Context, region string, ignoreExisting, withLock bool) *probe.Error
|
||||||
// Object lock config
|
// Object lock config
|
||||||
SetObjectLockConfig(mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error
|
SetObjectLockConfig(ctx context.Context, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error
|
||||||
GetObjectLockConfig() (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, perr *probe.Error)
|
GetObjectLockConfig(ctx context.Context) (mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, perr *probe.Error)
|
||||||
|
|
||||||
// Access policy operations.
|
// Access policy operations.
|
||||||
GetAccess() (access string, policyJSON string, error *probe.Error)
|
GetAccess(ctx context.Context) (access string, policyJSON string, error *probe.Error)
|
||||||
GetAccessRules() (policyRules map[string]string, error *probe.Error)
|
GetAccessRules(ctx context.Context) (policyRules map[string]string, error *probe.Error)
|
||||||
SetAccess(access string, isJSON bool) *probe.Error
|
SetAccess(ctx context.Context, access string, isJSON bool) *probe.Error
|
||||||
|
|
||||||
// I/O operations
|
// I/O operations
|
||||||
Copy(source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart bool) *probe.Error
|
Copy(ctx context.Context, source string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart, isPreserve bool) *probe.Error
|
||||||
|
|
||||||
// Runs select expression on object storage on specific files.
|
// Runs select expression on object storage on specific files.
|
||||||
Select(expression string, sse encrypt.ServerSide, opts SelectObjectOpts) (io.ReadCloser, *probe.Error)
|
Select(ctx context.Context, expression string, sse encrypt.ServerSide, opts SelectObjectOpts) (io.ReadCloser, *probe.Error)
|
||||||
|
|
||||||
// I/O operations with metadata.
|
// I/O operations with metadata.
|
||||||
Get(sse encrypt.ServerSide) (reader io.ReadCloser, err *probe.Error)
|
Get(ctx context.Context, sse encrypt.ServerSide) (reader io.ReadCloser, err *probe.Error)
|
||||||
Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (n int64, err *probe.Error)
|
Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart, isPreserve bool) (n int64, err *probe.Error)
|
||||||
|
|
||||||
// Object Locking related API
|
// Object Locking related API
|
||||||
PutObjectRetention(mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error
|
PutObjectRetention(ctx context.Context, mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error
|
||||||
PutObjectLegalHold(hold minio.LegalHoldStatus) *probe.Error
|
PutObjectLegalHold(ctx context.Context, hold minio.LegalHoldStatus) *probe.Error
|
||||||
|
|
||||||
// I/O operations with expiration
|
// I/O operations with expiration
|
||||||
ShareDownload(expires time.Duration) (string, *probe.Error)
|
ShareDownload(ctx context.Context, expires time.Duration) (string, *probe.Error)
|
||||||
ShareUpload(bool, time.Duration, string) (string, map[string]string, *probe.Error)
|
ShareUpload(bool, time.Duration, string) (string, map[string]string, *probe.Error)
|
||||||
|
|
||||||
// Watch events
|
// Watch events
|
||||||
Watch(options WatchOptions) (*WatchObject, *probe.Error)
|
Watch(ctx context.Context, options WatchOptions) (*WatchObject, *probe.Error)
|
||||||
|
|
||||||
// Delete operations
|
// Delete operations
|
||||||
Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) (errorCh <-chan *probe.Error)
|
Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) (errorCh <-chan *probe.Error)
|
||||||
// GetURL returns back internal url
|
// GetURL returns back internal url
|
||||||
GetURL() ClientURL
|
GetURL() ClientURL
|
||||||
|
|
||||||
AddUserAgent(app, version string)
|
AddUserAgent(app, version string)
|
||||||
|
|
||||||
// Tagging operations
|
// Tagging operations
|
||||||
GetTags() (*tags.Tags, *probe.Error)
|
GetTags(ctx context.Context) (*tags.Tags, *probe.Error)
|
||||||
SetTags(tags string) *probe.Error
|
SetTags(ctx context.Context, tags string) *probe.Error
|
||||||
DeleteTags() *probe.Error
|
DeleteTags(ctx context.Context) *probe.Error
|
||||||
|
|
||||||
// Lifecycle operations
|
// Lifecycle operations
|
||||||
GetLifecycle() (ilm.LifecycleConfiguration, *probe.Error)
|
GetLifecycle(ctx context.Context) (ilm.LifecycleConfiguration, *probe.Error)
|
||||||
SetLifecycle(lfcCfg ilm.LifecycleConfiguration) *probe.Error
|
SetLifecycle(ctx context.Context, lfcCfg ilm.LifecycleConfiguration) *probe.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientContent - Content container for content metadata
|
// ClientContent - Content container for content metadata
|
||||||
|
|||||||
+52
-39
@@ -104,10 +104,10 @@ func getEncKeys(ctx *cli.Context) (map[string][]prefixSSEPair, *probe.Error) {
|
|||||||
// Check if the passed URL represents a folder. It may or may not exist yet.
|
// Check if the passed URL represents a folder. It may or may not exist yet.
|
||||||
// If it exists, we can easily check if it is a folder, if it doesn't exist,
|
// If it exists, we can easily check if it is a folder, if it doesn't exist,
|
||||||
// we can guess if the url is a folder from how it looks.
|
// we can guess if the url is a folder from how it looks.
|
||||||
func isAliasURLDir(aliasURL string, keys map[string][]prefixSSEPair) bool {
|
func isAliasURLDir(ctx context.Context, aliasURL string, keys map[string][]prefixSSEPair) bool {
|
||||||
// If the target url exists, check if it is a directory
|
// If the target url exists, check if it is a directory
|
||||||
// and return immediately.
|
// and return immediately.
|
||||||
_, targetContent, err := url2Stat(aliasURL, false, keys)
|
_, targetContent, err := url2Stat(ctx, aliasURL, false, keys)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return targetContent.Type.IsDir()
|
return targetContent.Type.IsDir()
|
||||||
}
|
}
|
||||||
@@ -141,24 +141,24 @@ func isAliasURLDir(aliasURL string, keys map[string][]prefixSSEPair) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getSourceStreamMetadataFromURL gets a reader from URL.
|
// getSourceStreamMetadataFromURL gets a reader from URL.
|
||||||
func getSourceStreamMetadataFromURL(urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser,
|
func getSourceStreamMetadataFromURL(ctx context.Context, urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser,
|
||||||
metadata map[string]string, err *probe.Error) {
|
metadata map[string]string, err *probe.Error) {
|
||||||
alias, urlStrFull, _, err := expandAlias(urlStr)
|
alias, urlStrFull, _, err := expandAlias(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(urlStr)
|
return nil, nil, err.Trace(urlStr)
|
||||||
}
|
}
|
||||||
sseKey := getSSE(urlStr, encKeyDB[alias])
|
sseKey := getSSE(urlStr, encKeyDB[alias])
|
||||||
return getSourceStream(alias, urlStrFull, true, sseKey, false)
|
return getSourceStream(ctx, alias, urlStrFull, true, sseKey, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSourceStreamFromURL gets a reader from URL.
|
// getSourceStreamFromURL gets a reader from URL.
|
||||||
func getSourceStreamFromURL(urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser, err *probe.Error) {
|
func getSourceStreamFromURL(ctx context.Context, urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser, err *probe.Error) {
|
||||||
alias, urlStrFull, _, err := expandAlias(urlStr)
|
alias, urlStrFull, _, err := expandAlias(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(urlStr)
|
return nil, err.Trace(urlStr)
|
||||||
}
|
}
|
||||||
sse := getSSE(urlStr, encKeyDB[alias])
|
sse := getSSE(urlStr, encKeyDB[alias])
|
||||||
reader, _, err = getSourceStream(alias, urlStrFull, false, sse, false)
|
reader, _, err = getSourceStream(ctx, alias, urlStrFull, false, sse, false)
|
||||||
return reader, err
|
return reader, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +210,12 @@ func isReadAt(reader io.Reader) (ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getSourceStream gets a reader from URL.
|
// getSourceStream gets a reader from URL.
|
||||||
func getSourceStream(alias string, urlStr string, fetchStat bool, sse encrypt.ServerSide, preserve bool) (reader io.ReadCloser, metadata map[string]string, err *probe.Error) {
|
func getSourceStream(ctx context.Context, alias string, urlStr string, fetchStat bool, sse encrypt.ServerSide, preserve bool) (reader io.ReadCloser, metadata map[string]string, err *probe.Error) {
|
||||||
sourceClnt, err := newClientFromAlias(alias, urlStr)
|
sourceClnt, err := newClientFromAlias(alias, urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(alias, urlStr)
|
return nil, nil, err.Trace(alias, urlStr)
|
||||||
}
|
}
|
||||||
reader, err = sourceClnt.Get(sse)
|
reader, err = sourceClnt.Get(ctx, sse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(alias, urlStr)
|
return nil, nil, err.Trace(alias, urlStr)
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ func getSourceStream(alias string, urlStr string, fetchStat bool, sse encrypt.Se
|
|||||||
}
|
}
|
||||||
st.ETag = oinfo.ETag
|
st.ETag = oinfo.ETag
|
||||||
} else {
|
} else {
|
||||||
st, err = sourceClnt.Stat(false, preserve, sse)
|
st, err = sourceClnt.Stat(ctx, false, preserve, sse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err.Trace(alias, urlStr)
|
return nil, nil, err.Trace(alias, urlStr)
|
||||||
}
|
}
|
||||||
@@ -290,14 +290,14 @@ func putTargetRetention(ctx context.Context, alias string, urlStr string, metada
|
|||||||
retainUntilDate = t.UTC()
|
retainUntilDate = t.UTC()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := targetClnt.PutObjectRetention(lockMode, retainUntilDate, false); err != nil {
|
if err := targetClnt.PutObjectRetention(ctx, lockMode, retainUntilDate, false); err != nil {
|
||||||
return err.Trace(alias, urlStr)
|
return err.Trace(alias, urlStr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// putTargetStream writes to URL from Reader.
|
// putTargetStream writes to URL from Reader.
|
||||||
func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) {
|
func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold string, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart, preserve bool) (int64, *probe.Error) {
|
||||||
targetClnt, err := newClientFromAlias(alias, urlStr)
|
targetClnt, err := newClientFromAlias(alias, urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err.Trace(alias, urlStr)
|
return 0, err.Trace(alias, urlStr)
|
||||||
@@ -312,7 +312,7 @@ func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold
|
|||||||
if legalHold != "" {
|
if legalHold != "" {
|
||||||
metadata[AmzObjectLockLegalHold] = legalHold
|
metadata[AmzObjectLockLegalHold] = legalHold
|
||||||
}
|
}
|
||||||
n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse, md5, disableMultipart)
|
n, err := targetClnt.Put(ctx, reader, size, metadata, progress, sse, md5, disableMultipart, preserve)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err.Trace(alias, urlStr)
|
return n, err.Trace(alias, urlStr)
|
||||||
}
|
}
|
||||||
@@ -320,7 +320,7 @@ func putTargetStream(ctx context.Context, alias, urlStr, mode, until, legalHold
|
|||||||
}
|
}
|
||||||
|
|
||||||
// putTargetStreamWithURL writes to URL from reader. If length=-1, read until EOF.
|
// putTargetStreamWithURL writes to URL from reader. If length=-1, read until EOF.
|
||||||
func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide, md5, disableMultipart bool, metadata map[string]string) (int64, *probe.Error) {
|
func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse encrypt.ServerSide, md5, disableMultipart, preserve bool, metadata map[string]string) (int64, *probe.Error) {
|
||||||
alias, urlStrFull, _, err := expandAlias(urlStr)
|
alias, urlStrFull, _, err := expandAlias(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err.Trace(alias, urlStr)
|
return 0, err.Trace(alias, urlStr)
|
||||||
@@ -330,11 +330,11 @@ func putTargetStreamWithURL(urlStr string, reader io.Reader, size int64, sse enc
|
|||||||
metadata = map[string]string{}
|
metadata = map[string]string{}
|
||||||
}
|
}
|
||||||
metadata["Content-Type"] = contentType
|
metadata["Content-Type"] = contentType
|
||||||
return putTargetStream(context.Background(), alias, urlStrFull, "", "", "", reader, size, metadata, nil, sse, md5, disableMultipart)
|
return putTargetStream(context.Background(), alias, urlStrFull, "", "", "", reader, size, metadata, nil, sse, md5, disableMultipart, preserve)
|
||||||
}
|
}
|
||||||
|
|
||||||
// copySourceToTargetURL copies to targetURL from source.
|
// copySourceToTargetURL copies to targetURL from source.
|
||||||
func copySourceToTargetURL(alias, urlStr, source, mode, until, legalHold string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart bool) *probe.Error {
|
func copySourceToTargetURL(ctx context.Context, alias, urlStr, source, mode, until, legalHold string, size int64, progress io.Reader, srcSSE, tgtSSE encrypt.ServerSide, metadata map[string]string, disableMultipart bool) *probe.Error {
|
||||||
|
|
||||||
targetClnt, err := newClientFromAlias(alias, urlStr)
|
targetClnt, err := newClientFromAlias(alias, urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -344,7 +344,7 @@ func copySourceToTargetURL(alias, urlStr, source, mode, until, legalHold string,
|
|||||||
metadata[AmzObjectLockMode] = mode
|
metadata[AmzObjectLockMode] = mode
|
||||||
metadata[AmzObjectLockRetainUntilDate] = until
|
metadata[AmzObjectLockRetainUntilDate] = until
|
||||||
metadata[AmzObjectLockLegalHold] = legalHold
|
metadata[AmzObjectLockLegalHold] = legalHold
|
||||||
err = targetClnt.Copy(source, size, progress, srcSSE, tgtSSE, metadata, disableMultipart)
|
err = targetClnt.Copy(ctx, source, size, progress, srcSSE, tgtSSE, metadata, disableMultipart, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Trace(alias, urlStr)
|
return err.Trace(alias, urlStr)
|
||||||
@@ -369,23 +369,23 @@ func filterMetadata(metadata map[string]string) map[string]string {
|
|||||||
|
|
||||||
// getAllMetadata - returns a map of user defined function
|
// getAllMetadata - returns a map of user defined function
|
||||||
// by combining the usermetadata of object and values passed by attr keyword
|
// by combining the usermetadata of object and values passed by attr keyword
|
||||||
func getAllMetadata(sourceAlias, sourceURLStr string, srcSSE encrypt.ServerSide, urls URLs, preserve bool) (map[string]string, *probe.Error) {
|
func getAllMetadata(ctx context.Context, sourceAlias, sourceURLStr string, srcSSE encrypt.ServerSide, urls URLs, preserve bool) (map[string]string, *probe.Error) {
|
||||||
metadata := make(map[string]string)
|
metadata := make(map[string]string)
|
||||||
sourceClnt, err := newClientFromAlias(sourceAlias, sourceURLStr)
|
sourceClnt, err := newClientFromAlias(sourceAlias, sourceURLStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(sourceAlias, sourceURLStr)
|
return nil, err.Trace(sourceAlias, sourceURLStr)
|
||||||
}
|
}
|
||||||
st, err := sourceClnt.Stat(false, preserve, srcSSE)
|
st, err := sourceClnt.Stat(ctx, false, preserve, srcSSE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(sourceAlias, sourceURLStr)
|
return nil, err.Trace(sourceAlias, sourceURLStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range st.Metadata {
|
for k, v := range st.Metadata {
|
||||||
metadata[k] = v
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range urls.TargetContent.UserMetadata {
|
for k, v := range urls.TargetContent.UserMetadata {
|
||||||
metadata[k] = v
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterMetadata(metadata), nil
|
return filterMetadata(metadata), nil
|
||||||
@@ -455,47 +455,59 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
|
|||||||
if sourceAlias == targetAlias {
|
if sourceAlias == targetAlias {
|
||||||
// If no metadata populated already by the caller
|
// If no metadata populated already by the caller
|
||||||
// just do a Stat() to obtain the metadata.
|
// just do a Stat() to obtain the metadata.
|
||||||
if len(metadata) == 0 {
|
if len(metadata) == 0 && preserve {
|
||||||
metadata, err = getAllMetadata(sourceAlias, sourceURL.String(), srcSSE, urls, preserve)
|
metadata, err = getAllMetadata(ctx, sourceAlias, sourceURL.String(), srcSSE, urls, preserve)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return urls.WithError(err.Trace(sourceURL.String()))
|
return urls.WithError(err.Trace(sourceURL.String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get metadata from target content as well
|
||||||
|
for k, v := range urls.TargetContent.Metadata {
|
||||||
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get userMetadata from target content as well
|
||||||
|
for k, v := range urls.TargetContent.UserMetadata {
|
||||||
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
|
}
|
||||||
|
|
||||||
sourcePath := filepath.ToSlash(sourceURL.Path)
|
sourcePath := filepath.ToSlash(sourceURL.Path)
|
||||||
if urls.SourceContent.RetentionEnabled {
|
if urls.SourceContent.RetentionEnabled {
|
||||||
err = putTargetRetention(ctx, targetAlias, targetURL.String(), metadata)
|
err = putTargetRetention(ctx, targetAlias, targetURL.String(), metadata)
|
||||||
return urls.WithError(err.Trace(sourceURL.String()))
|
return urls.WithError(err.Trace(sourceURL.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get metadata from target content as well
|
err = copySourceToTargetURL(ctx, targetAlias, targetURL.String(), sourcePath, mode, until,
|
||||||
for k, v := range urls.TargetContent.Metadata {
|
|
||||||
metadata[k] = v
|
|
||||||
}
|
|
||||||
// Get userMetadata from target content as well
|
|
||||||
for k, v := range urls.TargetContent.UserMetadata {
|
|
||||||
metadata[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
err = copySourceToTargetURL(targetAlias, targetURL.String(), sourcePath, mode, until,
|
|
||||||
legalHold, length, progress, srcSSE, tgtSSE, filterMetadata(metadata), urls.DisableMultipart)
|
legalHold, length, progress, srcSSE, tgtSSE, filterMetadata(metadata), urls.DisableMultipart)
|
||||||
} else {
|
} else {
|
||||||
if urls.SourceContent.RetentionEnabled {
|
if urls.SourceContent.RetentionEnabled {
|
||||||
// If no metadata populated already by the caller
|
// If no metadata populated already by the caller
|
||||||
// just do a Stat() to obtain the metadata.
|
// just do a Stat() to obtain the metadata.
|
||||||
if len(metadata) == 0 {
|
if len(metadata) == 0 && preserve {
|
||||||
metadata, err = getAllMetadata(sourceAlias, sourceURL.String(), srcSSE, urls, preserve)
|
metadata, err = getAllMetadata(ctx, sourceAlias, sourceURL.String(), srcSSE, urls, preserve)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return urls.WithError(err.Trace(sourceURL.String()))
|
return urls.WithError(err.Trace(sourceURL.String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get metadata from target content as well
|
||||||
|
for k, v := range urls.TargetContent.Metadata {
|
||||||
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get userMetadata from target content as well
|
||||||
|
for k, v := range urls.TargetContent.UserMetadata {
|
||||||
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
|
}
|
||||||
|
|
||||||
err = putTargetRetention(ctx, targetAlias, targetURL.String(), metadata)
|
err = putTargetRetention(ctx, targetAlias, targetURL.String(), metadata)
|
||||||
return urls.WithError(err.Trace(sourceURL.String()))
|
return urls.WithError(err.Trace(sourceURL.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader io.ReadCloser
|
var reader io.ReadCloser
|
||||||
// Proceed with regular stream copy.
|
// Proceed with regular stream copy.
|
||||||
reader, metadata, err = getSourceStream(sourceAlias, sourceURL.String(), true, srcSSE, preserve)
|
reader, metadata, err = getSourceStream(ctx, sourceAlias, sourceURL.String(), true, srcSSE, preserve)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return urls.WithError(err.Trace(sourceURL.String()))
|
return urls.WithError(err.Trace(sourceURL.String()))
|
||||||
}
|
}
|
||||||
@@ -503,22 +515,23 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
|
|||||||
|
|
||||||
// Get metadata from target content as well
|
// Get metadata from target content as well
|
||||||
for k, v := range urls.TargetContent.Metadata {
|
for k, v := range urls.TargetContent.Metadata {
|
||||||
metadata[k] = v
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get userMetadata from target content as well
|
// Get userMetadata from target content as well
|
||||||
for k, v := range urls.TargetContent.UserMetadata {
|
for k, v := range urls.TargetContent.UserMetadata {
|
||||||
metadata[k] = v
|
metadata[http.CanonicalHeaderKey(k)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
if isReadAt(reader) {
|
if isReadAt(reader) {
|
||||||
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
||||||
legalHold, reader, length, filterMetadata(metadata),
|
legalHold, reader, length, filterMetadata(metadata),
|
||||||
progress, tgtSSE, urls.MD5, urls.DisableMultipart)
|
progress, tgtSSE, urls.MD5, urls.DisableMultipart, preserve)
|
||||||
} else {
|
} else {
|
||||||
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
_, err = putTargetStream(ctx, targetAlias, targetURL.String(), mode, until,
|
||||||
legalHold, io.LimitReader(reader, length),
|
legalHold, io.LimitReader(reader, length),
|
||||||
length, filterMetadata(metadata), progress, tgtSSE, urls.MD5,
|
length, filterMetadata(metadata), progress, tgtSSE, urls.MD5,
|
||||||
urls.DisableMultipart)
|
urls.DisableMultipart, preserve)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+16
-12
@@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
@@ -49,7 +50,7 @@ var configHostAddCmd = cli.Command{
|
|||||||
ShortName: "a",
|
ShortName: "a",
|
||||||
Usage: "add a new host to configuration file",
|
Usage: "add a new host to configuration file",
|
||||||
Action: mainConfigHostAdd,
|
Action: mainConfigHostAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(hostAddFlags, globalFlags...),
|
Flags: append(hostAddFlags, globalFlags...),
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
@@ -159,7 +160,7 @@ func addHost(alias string, hostCfgV9 hostConfigV9) {
|
|||||||
|
|
||||||
// probeS3Signature - auto probe S3 server signature: issue a Stat call
|
// probeS3Signature - auto probe S3 server signature: issue a Stat call
|
||||||
// using v4 signature then v2 in case of failure.
|
// using v4 signature then v2 in case of failure.
|
||||||
func probeS3Signature(accessKey, secretKey, url string) (string, *probe.Error) {
|
func probeS3Signature(ctx context.Context, accessKey, secretKey, url string) (string, *probe.Error) {
|
||||||
probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-")
|
probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-")
|
||||||
// Test s3 connection for API auto probe
|
// Test s3 connection for API auto probe
|
||||||
s3Config := &Config{
|
s3Config := &Config{
|
||||||
@@ -178,7 +179,7 @@ func probeS3Signature(accessKey, secretKey, url string) (string, *probe.Error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s3Client.Stat(false, false, nil); err != nil {
|
if _, err := s3Client.Stat(ctx, false, false, nil); err != nil {
|
||||||
e := err.ToGoError()
|
e := err.ToGoError()
|
||||||
if _, ok := e.(BucketDoesNotExist); ok {
|
if _, ok := e.(BucketDoesNotExist); ok {
|
||||||
// Bucket doesn't exist, means signature probing worked successfully.
|
// Bucket doesn't exist, means signature probing worked successfully.
|
||||||
@@ -209,7 +210,7 @@ func probeS3Signature(accessKey, secretKey, url string) (string, *probe.Error) {
|
|||||||
|
|
||||||
// BuildS3Config constructs an S3 Config and does
|
// BuildS3Config constructs an S3 Config and does
|
||||||
// signature auto-probe when needed.
|
// signature auto-probe when needed.
|
||||||
func BuildS3Config(url, accessKey, secretKey, api, lookup string) (*Config, *probe.Error) {
|
func BuildS3Config(ctx context.Context, url, accessKey, secretKey, api, lookup string) (*Config, *probe.Error) {
|
||||||
|
|
||||||
s3Config := NewS3Config(url, &hostConfigV9{
|
s3Config := NewS3Config(url, &hostConfigV9{
|
||||||
AccessKey: accessKey,
|
AccessKey: accessKey,
|
||||||
@@ -225,7 +226,7 @@ func BuildS3Config(url, accessKey, secretKey, api, lookup string) (*Config, *pro
|
|||||||
return s3Config, nil
|
return s3Config, nil
|
||||||
}
|
}
|
||||||
// Probe S3 signature version
|
// Probe S3 signature version
|
||||||
api, err := probeS3Signature(accessKey, secretKey, url)
|
api, err := probeS3Signature(ctx, accessKey, secretKey, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Trace(url, accessKey, secretKey, api, lookup)
|
return nil, err.Trace(url, accessKey, secretKey, api, lookup)
|
||||||
}
|
}
|
||||||
@@ -272,21 +273,24 @@ func fetchHostKeys(args cli.Args) (string, string) {
|
|||||||
return accessKey, secretKey
|
return accessKey, secretKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainConfigHostAdd(ctx *cli.Context) error {
|
func mainConfigHostAdd(cli *cli.Context) error {
|
||||||
|
|
||||||
console.SetColor("HostMessage", color.New(color.FgGreen))
|
console.SetColor("HostMessage", color.New(color.FgGreen))
|
||||||
var (
|
var (
|
||||||
args = ctx.Args()
|
args = cli.Args()
|
||||||
alias = cleanAlias(args.Get(0))
|
alias = cleanAlias(args.Get(0))
|
||||||
url = trimTrailingSeparator(args.Get(1))
|
url = trimTrailingSeparator(args.Get(1))
|
||||||
api = ctx.String("api")
|
api = cli.String("api")
|
||||||
lookup = ctx.String("lookup")
|
lookup = cli.String("lookup")
|
||||||
)
|
)
|
||||||
accessKey, secretKey := fetchHostKeys(args)
|
accessKey, secretKey := fetchHostKeys(args)
|
||||||
checkConfigHostAddSyntax(ctx, accessKey, secretKey)
|
checkConfigHostAddSyntax(cli, accessKey, secretKey)
|
||||||
|
|
||||||
s3Config, err := BuildS3Config(url, accessKey, secretKey, api, lookup)
|
ctx, cancelHostAdd := context.WithCancel(globalContext)
|
||||||
fatalIf(err.Trace(ctx.Args()...), "Unable to initialize new config from the provided credentials.")
|
defer cancelHostAdd()
|
||||||
|
|
||||||
|
s3Config, err := BuildS3Config(ctx, url, accessKey, secretKey, api, lookup)
|
||||||
|
fatalIf(err.Trace(cli.Args()...), "Unable to initialize new config from the provided credentials.")
|
||||||
|
|
||||||
addHost(alias, hostConfigV9{
|
addHost(alias, hostConfigV9{
|
||||||
URL: s3Config.HostURL,
|
URL: s3Config.HostURL,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var configHostListCmd = cli.Command{
|
|||||||
ShortName: "ls",
|
ShortName: "ls",
|
||||||
Usage: "list hosts in configuration file",
|
Usage: "list hosts in configuration file",
|
||||||
Action: mainConfigHostList,
|
Action: mainConfigHostList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var configHostRemoveCmd = cli.Command{
|
|||||||
ShortName: "rm",
|
ShortName: "rm",
|
||||||
Usage: "remove a host from configuration file",
|
Usage: "remove a host from configuration file",
|
||||||
Action: mainConfigHostRemove,
|
Action: mainConfigHostRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ var configHostCmd = cli.Command{
|
|||||||
Name: "host",
|
Name: "host",
|
||||||
Usage: "add, remove and list hosts in configuration file",
|
Usage: "add, remove and list hosts in configuration file",
|
||||||
Action: mainConfigHost,
|
Action: mainConfigHost,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
configHostAddCmd,
|
configHostAddCmd,
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ var configCmd = cli.Command{
|
|||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "configure MinIO client",
|
Usage: "configure MinIO client",
|
||||||
Action: mainConfig,
|
Action: mainConfig,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Flags: append(configFlags, globalFlags...),
|
Flags: append(configFlags, globalFlags...),
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
|
|||||||
+39
-39
@@ -104,7 +104,7 @@ var cpCmd = cli.Command{
|
|||||||
Name: "cp",
|
Name: "cp",
|
||||||
Usage: "copy objects",
|
Usage: "copy objects",
|
||||||
Action: mainCopy,
|
Action: mainCopy,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(append(cpFlags, ioFlags...), globalFlags...),
|
Flags: append(append(cpFlags, ioFlags...), globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -244,28 +244,28 @@ func doCopy(ctx context.Context, cpURLs URLs, pg ProgressReader, encKeyDB map[st
|
|||||||
|
|
||||||
urls := uploadSourceToTargetURL(ctx, cpURLs, pg, encKeyDB, preserve)
|
urls := uploadSourceToTargetURL(ctx, cpURLs, pg, encKeyDB, preserve)
|
||||||
if isMvCmd && urls.Error == nil {
|
if isMvCmd && urls.Error == nil {
|
||||||
bgRemove(sourcePath)
|
bgRemove(ctx, sourcePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls
|
return urls
|
||||||
}
|
}
|
||||||
|
|
||||||
// doCopyFake - Perform a fake copy to update the progress bar appropriately.
|
// doCopyFake - Perform a fake copy to update the progress bar appropriately.
|
||||||
func doCopyFake(cpURLs URLs, pg Progress, isMvCmd bool) URLs {
|
func doCopyFake(ctx context.Context, cpURLs URLs, pg Progress, isMvCmd bool) URLs {
|
||||||
if progressReader, ok := pg.(*progressBar); ok {
|
if progressReader, ok := pg.(*progressBar); ok {
|
||||||
progressReader.ProgressBar.Add64(cpURLs.SourceContent.Size)
|
progressReader.ProgressBar.Add64(cpURLs.SourceContent.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isMvCmd {
|
if isMvCmd {
|
||||||
sourcePath := filepath.ToSlash(filepath.Join(cpURLs.SourceAlias, cpURLs.SourceContent.URL.Path))
|
sourcePath := filepath.ToSlash(filepath.Join(cpURLs.SourceAlias, cpURLs.SourceContent.URL.Path))
|
||||||
bgRemove(sourcePath)
|
bgRemove(ctx, sourcePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cpURLs
|
return cpURLs
|
||||||
}
|
}
|
||||||
|
|
||||||
// doPrepareCopyURLs scans the source URL and prepares a list of objects for copying.
|
// doPrepareCopyURLs scans the source URL and prepares a list of objects for copying.
|
||||||
func doPrepareCopyURLs(session *sessionV8, cancelCopy context.CancelFunc) (totalBytes, totalObjects int64) {
|
func doPrepareCopyURLs(ctx context.Context, session *sessionV8, cancelCopy context.CancelFunc) (totalBytes, totalObjects int64) {
|
||||||
// Separate source and target. 'cp' can take only one target,
|
// Separate source and target. 'cp' can take only one target,
|
||||||
// but any number of sources.
|
// but any number of sources.
|
||||||
sourceURLs := session.Header.CommandArgs[:len(session.Header.CommandArgs)-1]
|
sourceURLs := session.Header.CommandArgs[:len(session.Header.CommandArgs)-1]
|
||||||
@@ -289,7 +289,7 @@ func doPrepareCopyURLs(session *sessionV8, cancelCopy context.CancelFunc) (total
|
|||||||
scanBar = scanBarFactory()
|
scanBar = scanBarFactory()
|
||||||
}
|
}
|
||||||
|
|
||||||
URLsCh := prepareCopyURLs(sourceURLs, targetURL, isRecursive, encKeyDB, olderThan, newerThan)
|
URLsCh := prepareCopyURLs(ctx, sourceURLs, targetURL, isRecursive, encKeyDB, olderThan, newerThan)
|
||||||
done := false
|
done := false
|
||||||
for !done {
|
for !done {
|
||||||
select {
|
select {
|
||||||
@@ -341,10 +341,7 @@ func doPrepareCopyURLs(session *sessionV8, cancelCopy context.CancelFunc) (total
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]prefixSSEPair, isMvCmd bool) error {
|
func doCopySession(ctx context.Context, cancelCopy context.CancelFunc, cli *cli.Context, session *sessionV8, encKeyDB map[string][]prefixSSEPair, isMvCmd bool) error {
|
||||||
ctx, cancelCopy := context.WithCancel(globalContext)
|
|
||||||
defer cancelCopy()
|
|
||||||
|
|
||||||
var isCopied func(string) bool
|
var isCopied func(string) bool
|
||||||
var totalObjects, totalBytes int64
|
var totalObjects, totalBytes int64
|
||||||
|
|
||||||
@@ -366,7 +363,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
|||||||
isCopied = isLastFactory(session.Header.LastCopied)
|
isCopied = isLastFactory(session.Header.LastCopied)
|
||||||
|
|
||||||
if !session.HasData() {
|
if !session.HasData() {
|
||||||
totalBytes, totalObjects = doPrepareCopyURLs(session, cancelCopy)
|
totalBytes, totalObjects = doPrepareCopyURLs(ctx, session, cancelCopy)
|
||||||
} else {
|
} else {
|
||||||
totalBytes, totalObjects = session.Header.TotalBytes, session.Header.TotalObjects
|
totalBytes, totalObjects = session.Header.TotalBytes, session.Header.TotalObjects
|
||||||
}
|
}
|
||||||
@@ -403,7 +400,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
totalBytes := int64(0)
|
totalBytes := int64(0)
|
||||||
for cpURLs := range prepareCopyURLs(sourceURLs, targetURL, isRecursive,
|
for cpURLs := range prepareCopyURLs(ctx, sourceURLs, targetURL, isRecursive,
|
||||||
encKeyDB, olderThan, newerThan) {
|
encKeyDB, olderThan, newerThan) {
|
||||||
if cpURLs.Error != nil {
|
if cpURLs.Error != nil {
|
||||||
// Print in new line and adjust to top so that we
|
// Print in new line and adjust to top so that we
|
||||||
@@ -478,7 +475,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
|||||||
cpURLs.TargetContent.RetentionEnabled = true
|
cpURLs.TargetContent.RetentionEnabled = true
|
||||||
}
|
}
|
||||||
cpURLs.TargetContent.RetentionDuration = session.Header.CommandStringFlags[rdFlag]
|
cpURLs.TargetContent.RetentionDuration = session.Header.CommandStringFlags[rdFlag]
|
||||||
cpURLs.TargetContent.LegalHold = session.Header.CommandStringFlags[lhFlag]
|
cpURLs.TargetContent.LegalHold = strings.ToUpper(session.Header.CommandStringFlags[lhFlag])
|
||||||
if cpURLs.TargetContent.LegalHold != "" {
|
if cpURLs.TargetContent.LegalHold != "" {
|
||||||
cpURLs.TargetContent.LegalHoldEnabled = true
|
cpURLs.TargetContent.LegalHoldEnabled = true
|
||||||
}
|
}
|
||||||
@@ -491,7 +488,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
|||||||
cpURLs.TargetContent.RetentionDuration = rd
|
cpURLs.TargetContent.RetentionDuration = rd
|
||||||
}
|
}
|
||||||
if lh := cli.String(lhFlag); lh != "" {
|
if lh := cli.String(lhFlag); lh != "" {
|
||||||
cpURLs.TargetContent.LegalHold = lh
|
cpURLs.TargetContent.LegalHold = strings.ToUpper(lh)
|
||||||
cpURLs.TargetContent.LegalHoldEnabled = true
|
cpURLs.TargetContent.LegalHoldEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,7 +506,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
|
|||||||
// Verify if previously copied, notify progress bar.
|
// Verify if previously copied, notify progress bar.
|
||||||
if isCopied != nil && isCopied(cpURLs.SourceContent.URL.String()) {
|
if isCopied != nil && isCopied(cpURLs.SourceContent.URL.String()) {
|
||||||
queueCh <- func() URLs {
|
queueCh <- func() URLs {
|
||||||
return doCopyFake(cpURLs, pg, isMvCmd)
|
return doCopyFake(ctx, cpURLs, pg, isMvCmd)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
queueCh <- func() URLs {
|
queueCh <- func() URLs {
|
||||||
@@ -618,33 +615,36 @@ func getMetaDataEntry(metadataString string) (map[string]string, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mainCopy is the entry point for cp command.
|
// mainCopy is the entry point for cp command.
|
||||||
func mainCopy(ctx *cli.Context) error {
|
func mainCopy(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelCopy := context.WithCancel(globalContext)
|
||||||
|
defer cancelCopy()
|
||||||
|
|
||||||
// Parse encryption keys per command.
|
// Parse encryption keys per command.
|
||||||
encKeyDB, err := getEncKeys(ctx)
|
encKeyDB, err := getEncKeys(cliCtx)
|
||||||
fatalIf(err, "Unable to parse encryption keys.")
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
|
|
||||||
// Parse metadata.
|
// Parse metadata.
|
||||||
userMetaMap := make(map[string]string)
|
userMetaMap := make(map[string]string)
|
||||||
if ctx.String("attr") != "" {
|
if cliCtx.String("attr") != "" {
|
||||||
userMetaMap, err = getMetaDataEntry(ctx.String("attr"))
|
userMetaMap, err = getMetaDataEntry(cliCtx.String("attr"))
|
||||||
fatalIf(err, "Unable to parse attribute %v", ctx.String("attr"))
|
fatalIf(err, "Unable to parse attribute %v", cliCtx.String("attr"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check 'copy' cli arguments.
|
// check 'copy' cli arguments.
|
||||||
checkCopySyntax(ctx, encKeyDB, false)
|
checkCopySyntax(ctx, cliCtx, encKeyDB, false)
|
||||||
|
|
||||||
// Additional command specific theme customization.
|
// Additional command specific theme customization.
|
||||||
console.SetColor("Copy", color.New(color.FgGreen, color.Bold))
|
console.SetColor("Copy", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
recursive := ctx.Bool("recursive")
|
recursive := cliCtx.Bool("recursive")
|
||||||
olderThan := ctx.String("older-than")
|
olderThan := cliCtx.String("older-than")
|
||||||
newerThan := ctx.String("newer-than")
|
newerThan := cliCtx.String("newer-than")
|
||||||
storageClass := ctx.String("storage-class")
|
storageClass := cliCtx.String("storage-class")
|
||||||
retentionMode := ctx.String(rmFlag)
|
retentionMode := cliCtx.String(rmFlag)
|
||||||
retentionDuration := ctx.String(rdFlag)
|
retentionDuration := cliCtx.String(rdFlag)
|
||||||
legalHold := ctx.String(lhFlag)
|
legalHold := strings.ToUpper(cliCtx.String(lhFlag))
|
||||||
sseKeys := os.Getenv("MC_ENCRYPT_KEY")
|
sseKeys := os.Getenv("MC_ENCRYPT_KEY")
|
||||||
if key := ctx.String("encrypt-key"); key != "" {
|
if key := cliCtx.String("encrypt-key"); key != "" {
|
||||||
sseKeys = key
|
sseKeys = key
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,12 +652,12 @@ func mainCopy(ctx *cli.Context) error {
|
|||||||
sseKeys, err = getDecodedKey(sseKeys)
|
sseKeys, err = getDecodedKey(sseKeys)
|
||||||
fatalIf(err, "Unable to parse encryption keys.")
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
}
|
}
|
||||||
sse := ctx.String("encrypt")
|
sse := cliCtx.String("encrypt")
|
||||||
|
|
||||||
var session *sessionV8
|
var session *sessionV8
|
||||||
|
|
||||||
if ctx.Bool("continue") {
|
if cliCtx.Bool("continue") {
|
||||||
sessionID := getHash("cp", ctx.Args())
|
sessionID := getHash("cp", cliCtx.Args())
|
||||||
if isSessionExists(sessionID) {
|
if isSessionExists(sessionID) {
|
||||||
session, err = loadSessionV8(sessionID)
|
session, err = loadSessionV8(sessionID)
|
||||||
fatalIf(err.Trace(sessionID), "Unable to load session.")
|
fatalIf(err.Trace(sessionID), "Unable to load session.")
|
||||||
@@ -673,14 +673,14 @@ func mainCopy(ctx *cli.Context) error {
|
|||||||
session.Header.CommandStringFlags[lhFlag] = legalHold
|
session.Header.CommandStringFlags[lhFlag] = legalHold
|
||||||
session.Header.CommandStringFlags["encrypt-key"] = sseKeys
|
session.Header.CommandStringFlags["encrypt-key"] = sseKeys
|
||||||
session.Header.CommandStringFlags["encrypt"] = sse
|
session.Header.CommandStringFlags["encrypt"] = sse
|
||||||
session.Header.CommandBoolFlags["session"] = ctx.Bool("continue")
|
session.Header.CommandBoolFlags["session"] = cliCtx.Bool("continue")
|
||||||
|
|
||||||
if ctx.Bool("preserve") {
|
if cliCtx.Bool("preserve") {
|
||||||
session.Header.CommandBoolFlags["preserve"] = ctx.Bool("preserve")
|
session.Header.CommandBoolFlags["preserve"] = cliCtx.Bool("preserve")
|
||||||
}
|
}
|
||||||
session.Header.UserMetaData = userMetaMap
|
session.Header.UserMetaData = userMetaMap
|
||||||
session.Header.CommandBoolFlags["md5"] = ctx.Bool("md5")
|
session.Header.CommandBoolFlags["md5"] = cliCtx.Bool("md5")
|
||||||
session.Header.CommandBoolFlags["disable-multipart"] = ctx.Bool("disable-multipart")
|
session.Header.CommandBoolFlags["disable-multipart"] = cliCtx.Bool("disable-multipart")
|
||||||
|
|
||||||
var e error
|
var e error
|
||||||
if session.Header.RootPath, e = os.Getwd(); e != nil {
|
if session.Header.RootPath, e = os.Getwd(); e != nil {
|
||||||
@@ -689,11 +689,11 @@ func mainCopy(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extract URLs.
|
// extract URLs.
|
||||||
session.Header.CommandArgs = ctx.Args()
|
session.Header.CommandArgs = cliCtx.Args()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e := doCopySession(ctx, session, encKeyDB, false)
|
e := doCopySession(ctx, cancelCopy, cliCtx, session, encKeyDB, false)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
session.Delete()
|
session.Delete()
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-26
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
@@ -24,27 +25,27 @@ import (
|
|||||||
"github.com/minio/minio/pkg/console"
|
"github.com/minio/minio/pkg/console"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkCopySyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair, isMvCmd bool) {
|
func checkCopySyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string][]prefixSSEPair, isMvCmd bool) {
|
||||||
if len(ctx.Args()) < 2 {
|
if len(cliCtx.Args()) < 2 {
|
||||||
if isMvCmd {
|
if isMvCmd {
|
||||||
cli.ShowCommandHelpAndExit(ctx, "mv", 1) // last argument is exit code.
|
cli.ShowCommandHelpAndExit(cliCtx, "mv", 1) // last argument is exit code.
|
||||||
}
|
}
|
||||||
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code.
|
cli.ShowCommandHelpAndExit(cliCtx, "cp", 1) // last argument is exit code.
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract URLs.
|
// extract URLs.
|
||||||
URLs := ctx.Args()
|
URLs := cliCtx.Args()
|
||||||
if len(URLs) < 2 {
|
if len(URLs) < 2 {
|
||||||
fatalIf(errDummy().Trace(ctx.Args()...), "Unable to parse source and target arguments.")
|
fatalIf(errDummy().Trace(cliCtx.Args()...), "Unable to parse source and target arguments.")
|
||||||
}
|
}
|
||||||
|
|
||||||
srcURLs := URLs[:len(URLs)-1]
|
srcURLs := URLs[:len(URLs)-1]
|
||||||
tgtURL := URLs[len(URLs)-1]
|
tgtURL := URLs[len(URLs)-1]
|
||||||
isRecursive := ctx.Bool("recursive")
|
isRecursive := cliCtx.Bool("recursive")
|
||||||
|
|
||||||
// Verify if source(s) exists.
|
// Verify if source(s) exists.
|
||||||
for _, srcURL := range srcURLs {
|
for _, srcURL := range srcURLs {
|
||||||
_, _, err := url2Stat(srcURL, false, encKeyDB)
|
_, _, err := url2Stat(ctx, srcURL, false, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalf("Unable to validate source %s\n", srcURL)
|
console.Fatalf("Unable to validate source %s\n", srcURL)
|
||||||
}
|
}
|
||||||
@@ -58,11 +59,11 @@ func checkCopySyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair, isMv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.String(rdFlag) != "" && ctx.String(rmFlag) == "" {
|
if cliCtx.String(rdFlag) != "" && cliCtx.String(rmFlag) == "" {
|
||||||
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Both object retention flags `--%s` and `--%s` are required.\n", rdFlag, rmFlag))
|
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Both object retention flags `--%s` and `--%s` are required.\n", rdFlag, rmFlag))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.String(rdFlag) == "" && ctx.String(rmFlag) != "" {
|
if cliCtx.String(rdFlag) == "" && cliCtx.String(rmFlag) != "" {
|
||||||
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Both object retention flags `--%s` and `--%s` are required.\n", rdFlag, rmFlag))
|
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Both object retention flags `--%s` and `--%s` are required.\n", rdFlag, rmFlag))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,38 +73,38 @@ func checkCopySyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair, isMv
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Guess CopyURLsType based on source and target URLs.
|
// Guess CopyURLsType based on source and target URLs.
|
||||||
copyURLsType, err := guessCopyURLType(srcURLs, tgtURL, isRecursive, encKeyDB)
|
copyURLsType, err := guessCopyURLType(ctx, srcURLs, tgtURL, isRecursive, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of "+operation+" operation.")
|
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of "+operation+" operation.")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch copyURLsType {
|
switch copyURLsType {
|
||||||
case copyURLsTypeA: // File -> File.
|
case copyURLsTypeA: // File -> File.
|
||||||
checkCopySyntaxTypeA(srcURLs, tgtURL, encKeyDB, isMvCmd)
|
checkCopySyntaxTypeA(ctx, srcURLs, tgtURL, encKeyDB, isMvCmd)
|
||||||
case copyURLsTypeB: // File -> Folder.
|
case copyURLsTypeB: // File -> Folder.
|
||||||
checkCopySyntaxTypeB(srcURLs, tgtURL, encKeyDB, isMvCmd)
|
checkCopySyntaxTypeB(ctx, srcURLs, tgtURL, encKeyDB, isMvCmd)
|
||||||
case copyURLsTypeC: // Folder... -> Folder.
|
case copyURLsTypeC: // Folder... -> Folder.
|
||||||
checkCopySyntaxTypeC(srcURLs, tgtURL, isRecursive, encKeyDB, isMvCmd)
|
checkCopySyntaxTypeC(ctx, srcURLs, tgtURL, isRecursive, encKeyDB, isMvCmd)
|
||||||
case copyURLsTypeD: // File1...FileN -> Folder.
|
case copyURLsTypeD: // File1...FileN -> Folder.
|
||||||
checkCopySyntaxTypeD(srcURLs, tgtURL, encKeyDB, isMvCmd)
|
checkCopySyntaxTypeD(ctx, srcURLs, tgtURL, encKeyDB, isMvCmd)
|
||||||
default:
|
default:
|
||||||
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of "+operation+" operation.")
|
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of "+operation+" operation.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserve functionality not supported for windows
|
// Preserve functionality not supported for windows
|
||||||
if ctx.Bool("preserve") && runtime.GOOS == "windows" {
|
if cliCtx.Bool("preserve") && runtime.GOOS == "windows" {
|
||||||
fatalIf(errInvalidArgument().Trace(), "Permissions are not preserved on windows platform.")
|
fatalIf(errInvalidArgument().Trace(), "Permissions are not preserved on windows platform.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkCopySyntaxTypeA verifies if the source and target are valid file arguments.
|
// checkCopySyntaxTypeA verifies if the source and target are valid file arguments.
|
||||||
func checkCopySyntaxTypeA(srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
func checkCopySyntaxTypeA(ctx context.Context, srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
||||||
// Check source.
|
// Check source.
|
||||||
if len(srcURLs) != 1 {
|
if len(srcURLs) != 1 {
|
||||||
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
||||||
}
|
}
|
||||||
srcURL := srcURLs[0]
|
srcURL := srcURLs[0]
|
||||||
_, srcContent, err := url2Stat(srcURL, false, keys)
|
_, srcContent, err := url2Stat(ctx, srcURL, false, keys)
|
||||||
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
|
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
|
||||||
|
|
||||||
if !srcContent.Type.IsRegular() {
|
if !srcContent.Type.IsRegular() {
|
||||||
@@ -112,13 +113,13 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string, keys map[string][]pre
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid folder.
|
// checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid folder.
|
||||||
func checkCopySyntaxTypeB(srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
func checkCopySyntaxTypeB(ctx context.Context, srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
||||||
// Check source.
|
// Check source.
|
||||||
if len(srcURLs) != 1 {
|
if len(srcURLs) != 1 {
|
||||||
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
||||||
}
|
}
|
||||||
srcURL := srcURLs[0]
|
srcURL := srcURLs[0]
|
||||||
_, srcContent, err := url2Stat(srcURL, false, keys)
|
_, srcContent, err := url2Stat(ctx, srcURL, false, keys)
|
||||||
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
|
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
|
||||||
|
|
||||||
if !srcContent.Type.IsRegular() {
|
if !srcContent.Type.IsRegular() {
|
||||||
@@ -126,7 +127,7 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string, keys map[string][]pre
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check target.
|
// Check target.
|
||||||
if _, tgtContent, err := url2Stat(tgtURL, false, keys); err == nil {
|
if _, tgtContent, err := url2Stat(ctx, tgtURL, false, keys); err == nil {
|
||||||
if !tgtContent.Type.IsDir() {
|
if !tgtContent.Type.IsDir() {
|
||||||
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
||||||
}
|
}
|
||||||
@@ -134,21 +135,21 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string, keys map[string][]pre
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkCopySyntaxTypeC verifies if the source is a valid recursive dir and target is a valid folder.
|
// checkCopySyntaxTypeC verifies if the source is a valid recursive dir and target is a valid folder.
|
||||||
func checkCopySyntaxTypeC(srcURLs []string, tgtURL string, isRecursive bool, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
func checkCopySyntaxTypeC(ctx context.Context, srcURLs []string, tgtURL string, isRecursive bool, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
||||||
// Check source.
|
// Check source.
|
||||||
if len(srcURLs) != 1 {
|
if len(srcURLs) != 1 {
|
||||||
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check target.
|
// Check target.
|
||||||
if _, tgtContent, err := url2Stat(tgtURL, false, keys); err == nil {
|
if _, tgtContent, err := url2Stat(ctx, tgtURL, false, keys); err == nil {
|
||||||
if !tgtContent.Type.IsDir() {
|
if !tgtContent.Type.IsDir() {
|
||||||
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, srcURL := range srcURLs {
|
for _, srcURL := range srcURLs {
|
||||||
c, srcContent, err := url2Stat(srcURL, false, keys)
|
c, srcContent, err := url2Stat(ctx, srcURL, false, keys)
|
||||||
// incomplete uploads are not necessary for copy operation, no need to verify for them.
|
// incomplete uploads are not necessary for copy operation, no need to verify for them.
|
||||||
isIncomplete := false
|
isIncomplete := false
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -183,10 +184,10 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string, isRecursive bool, key
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkCopySyntaxTypeD verifies if the source is a valid list of files and target is a valid folder.
|
// checkCopySyntaxTypeD verifies if the source is a valid list of files and target is a valid folder.
|
||||||
func checkCopySyntaxTypeD(srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
func checkCopySyntaxTypeD(ctx context.Context, srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool) {
|
||||||
// Source can be anything: file, dir, dir...
|
// Source can be anything: file, dir, dir...
|
||||||
// Check target if it is a dir
|
// Check target if it is a dir
|
||||||
if _, tgtContent, err := url2Stat(tgtURL, false, keys); err == nil {
|
if _, tgtContent, err := url2Stat(ctx, tgtURL, false, keys); err == nil {
|
||||||
if !tgtContent.Type.IsDir() {
|
if !tgtContent.Type.IsDir() {
|
||||||
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
fatalIf(errInvalidArgument().Trace(tgtURL), "Target `"+tgtURL+"` is not a folder.")
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-31
@@ -17,7 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -51,10 +51,10 @@ const (
|
|||||||
|
|
||||||
// guessCopyURLType guesses the type of clientURL. This approach all allows prepareURL
|
// guessCopyURLType guesses the type of clientURL. This approach all allows prepareURL
|
||||||
// functions to accurately report failure causes.
|
// functions to accurately report failure causes.
|
||||||
func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool, keys map[string][]prefixSSEPair) (copyURLsType, *probe.Error) {
|
func guessCopyURLType(ctx context.Context, sourceURLs []string, targetURL string, isRecursive bool, keys map[string][]prefixSSEPair) (copyURLsType, *probe.Error) {
|
||||||
if len(sourceURLs) == 1 { // 1 Source, 1 Target
|
if len(sourceURLs) == 1 { // 1 Source, 1 Target
|
||||||
sourceURL := sourceURLs[0]
|
sourceURL := sourceURLs[0]
|
||||||
_, sourceContent, err := url2Stat(sourceURL, false, keys)
|
_, sourceContent, err := url2Stat(ctx, sourceURL, false, keys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return copyURLsTypeInvalid, err
|
return copyURLsTypeInvalid, err
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool, k
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If target is a folder, it is Type B.
|
// If target is a folder, it is Type B.
|
||||||
if isAliasURLDir(targetURL, keys) {
|
if isAliasURLDir(ctx, targetURL, keys) {
|
||||||
return copyURLsTypeB, nil
|
return copyURLsTypeB, nil
|
||||||
}
|
}
|
||||||
// else Type A.
|
// else Type A.
|
||||||
@@ -74,7 +74,7 @@ func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool, k
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Multiple source args and target is a folder. It is Type D.
|
// Multiple source args and target is a folder. It is Type D.
|
||||||
if isAliasURLDir(targetURL, keys) {
|
if isAliasURLDir(ctx, targetURL, keys) {
|
||||||
return copyURLsTypeD, nil
|
return copyURLsTypeD, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,13 +83,13 @@ func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool, k
|
|||||||
|
|
||||||
// SINGLE SOURCE - Type A: copy(f, f) -> copy(f, f)
|
// SINGLE SOURCE - Type A: copy(f, f) -> copy(f, f)
|
||||||
// prepareCopyURLsTypeA - prepares target and source clientURLs for copying.
|
// prepareCopyURLsTypeA - prepares target and source clientURLs for copying.
|
||||||
func prepareCopyURLsTypeA(sourceURL string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs {
|
func prepareCopyURLsTypeA(ctx context.Context, sourceURL string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs {
|
||||||
// Extract alias before fiddling with the clientURL.
|
// Extract alias before fiddling with the clientURL.
|
||||||
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
||||||
// Find alias and expanded clientURL.
|
// Find alias and expanded clientURL.
|
||||||
targetAlias, targetURL, _ := mustExpandAlias(targetURL)
|
targetAlias, targetURL, _ := mustExpandAlias(targetURL)
|
||||||
|
|
||||||
_, sourceContent, err := url2Stat(sourceURL, false, encKeyDB)
|
_, sourceContent, err := url2Stat(ctx, sourceURL, false, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Source does not exist or insufficient privileges.
|
// Source does not exist or insufficient privileges.
|
||||||
return URLs{Error: err.Trace(sourceURL)}
|
return URLs{Error: err.Trace(sourceURL)}
|
||||||
@@ -116,13 +116,13 @@ func makeCopyContentTypeA(sourceAlias string, sourceContent *ClientContent, targ
|
|||||||
|
|
||||||
// SINGLE SOURCE - Type B: copy(f, d) -> copy(f, d/f) -> A
|
// SINGLE SOURCE - Type B: copy(f, d) -> copy(f, d/f) -> A
|
||||||
// prepareCopyURLsTypeB - prepares target and source clientURLs for copying.
|
// prepareCopyURLsTypeB - prepares target and source clientURLs for copying.
|
||||||
func prepareCopyURLsTypeB(sourceURL string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs {
|
func prepareCopyURLsTypeB(ctx context.Context, sourceURL string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs {
|
||||||
// Extract alias before fiddling with the clientURL.
|
// Extract alias before fiddling with the clientURL.
|
||||||
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
||||||
// Find alias and expanded clientURL.
|
// Find alias and expanded clientURL.
|
||||||
targetAlias, targetURL, _ := mustExpandAlias(targetURL)
|
targetAlias, targetURL, _ := mustExpandAlias(targetURL)
|
||||||
|
|
||||||
_, sourceContent, err := url2Stat(sourceURL, false, encKeyDB)
|
_, sourceContent, err := url2Stat(ctx, sourceURL, false, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Source does not exist or insufficient privileges.
|
// Source does not exist or insufficient privileges.
|
||||||
return URLs{Error: err.Trace(sourceURL)}
|
return URLs{Error: err.Trace(sourceURL)}
|
||||||
@@ -150,7 +150,7 @@ func makeCopyContentTypeB(sourceAlias string, sourceContent *ClientContent, targ
|
|||||||
|
|
||||||
// SINGLE SOURCE - Type C: copy(d1..., d2) -> []copy(d1/f, d1/d2/f) -> []A
|
// SINGLE SOURCE - Type C: copy(d1..., d2) -> []copy(d1/f, d1/d2/f) -> []A
|
||||||
// prepareCopyRecursiveURLTypeC - prepares target and source clientURLs for copying.
|
// prepareCopyRecursiveURLTypeC - prepares target and source clientURLs for copying.
|
||||||
func prepareCopyURLsTypeC(sourceURL, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair) <-chan URLs {
|
func prepareCopyURLsTypeC(ctx context.Context, sourceURL, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair) <-chan URLs {
|
||||||
// Extract alias before fiddling with the clientURL.
|
// Extract alias before fiddling with the clientURL.
|
||||||
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
sourceAlias, _, _ := mustExpandAlias(sourceURL)
|
||||||
// Find alias and expanded clientURL.
|
// Find alias and expanded clientURL.
|
||||||
@@ -166,7 +166,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string, isRecursive bool, encKeyD
|
|||||||
}
|
}
|
||||||
|
|
||||||
isIncomplete := false
|
isIncomplete := false
|
||||||
for sourceContent := range sourceClient.List(isRecursive, isIncomplete, false, DirNone) {
|
for sourceContent := range sourceClient.List(ctx, isRecursive, isIncomplete, false, DirNone) {
|
||||||
if sourceContent.Err != nil {
|
if sourceContent.Err != nil {
|
||||||
// Listing failed.
|
// Listing failed.
|
||||||
copyURLsCh <- URLs{Error: sourceContent.Err.Trace(sourceClient.GetURL().String())}
|
copyURLsCh <- URLs{Error: sourceContent.Err.Trace(sourceClient.GetURL().String())}
|
||||||
@@ -192,18 +192,6 @@ func makeCopyContentTypeC(sourceAlias string, sourceURL ClientURL, sourceContent
|
|||||||
newSourceSuffix := filepath.ToSlash(newSourceURL.Path)
|
newSourceSuffix := filepath.ToSlash(newSourceURL.Path)
|
||||||
if pathSeparatorIndex > 1 {
|
if pathSeparatorIndex > 1 {
|
||||||
sourcePrefix := filepath.ToSlash(sourceURL.Path[:pathSeparatorIndex])
|
sourcePrefix := filepath.ToSlash(sourceURL.Path[:pathSeparatorIndex])
|
||||||
// do not preserve unix cp behavior when copying a filesytem dir to
|
|
||||||
// objectstore.
|
|
||||||
if sourceAlias == "" && targetAlias != "" {
|
|
||||||
// Check if sourceURL.Path is a directory or not
|
|
||||||
fileInfo, err := os.Stat(sourceURL.Path)
|
|
||||||
if err != nil {
|
|
||||||
return URLs{Error: probe.NewError(err)}
|
|
||||||
}
|
|
||||||
if fileInfo.IsDir() {
|
|
||||||
sourcePrefix = filepath.ToSlash(sourceURL.Path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newSourceSuffix = strings.TrimPrefix(newSourceSuffix, sourcePrefix)
|
newSourceSuffix = strings.TrimPrefix(newSourceSuffix, sourcePrefix)
|
||||||
}
|
}
|
||||||
newTargetURL := urlJoinPath(targetURL, newSourceSuffix)
|
newTargetURL := urlJoinPath(targetURL, newSourceSuffix)
|
||||||
@@ -212,12 +200,12 @@ func makeCopyContentTypeC(sourceAlias string, sourceURL ClientURL, sourceContent
|
|||||||
|
|
||||||
// MULTI-SOURCE - Type D: copy([](f|d...), d) -> []B
|
// MULTI-SOURCE - Type D: copy([](f|d...), d) -> []B
|
||||||
// prepareCopyURLsTypeE - prepares target and source clientURLs for copying.
|
// prepareCopyURLsTypeE - prepares target and source clientURLs for copying.
|
||||||
func prepareCopyURLsTypeD(sourceURLs []string, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair) <-chan URLs {
|
func prepareCopyURLsTypeD(ctx context.Context, sourceURLs []string, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair) <-chan URLs {
|
||||||
copyURLsCh := make(chan URLs)
|
copyURLsCh := make(chan URLs)
|
||||||
go func(sourceURLs []string, targetURL string, copyURLsCh chan URLs) {
|
go func(sourceURLs []string, targetURL string, copyURLsCh chan URLs) {
|
||||||
defer close(copyURLsCh)
|
defer close(copyURLsCh)
|
||||||
for _, sourceURL := range sourceURLs {
|
for _, sourceURL := range sourceURLs {
|
||||||
for cpURLs := range prepareCopyURLsTypeC(sourceURL, targetURL, isRecursive, encKeyDB) {
|
for cpURLs := range prepareCopyURLsTypeC(ctx, sourceURL, targetURL, isRecursive, encKeyDB) {
|
||||||
copyURLsCh <- cpURLs
|
copyURLsCh <- cpURLs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,24 +214,24 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string, isRecursive boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepareCopyURLs - prepares target and source clientURLs for copying.
|
// prepareCopyURLs - prepares target and source clientURLs for copying.
|
||||||
func prepareCopyURLs(sourceURLs []string, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair, olderThan, newerThan string) chan URLs {
|
func prepareCopyURLs(ctx context.Context, sourceURLs []string, targetURL string, isRecursive bool, encKeyDB map[string][]prefixSSEPair, olderThan, newerThan string) chan URLs {
|
||||||
copyURLsCh := make(chan URLs)
|
copyURLsCh := make(chan URLs)
|
||||||
go func(sourceURLs []string, targetURL string, copyURLsCh chan URLs, encKeyDB map[string][]prefixSSEPair) {
|
go func(sourceURLs []string, targetURL string, copyURLsCh chan URLs, encKeyDB map[string][]prefixSSEPair) {
|
||||||
defer close(copyURLsCh)
|
defer close(copyURLsCh)
|
||||||
cpType, err := guessCopyURLType(sourceURLs, targetURL, isRecursive, encKeyDB)
|
cpType, err := guessCopyURLType(ctx, sourceURLs, targetURL, isRecursive, encKeyDB)
|
||||||
fatalIf(err.Trace(), "Unable to guess the type of copy operation.")
|
fatalIf(err.Trace(), "Unable to guess the type of copy operation.")
|
||||||
|
|
||||||
switch cpType {
|
switch cpType {
|
||||||
case copyURLsTypeA:
|
case copyURLsTypeA:
|
||||||
copyURLsCh <- prepareCopyURLsTypeA(sourceURLs[0], targetURL, encKeyDB)
|
copyURLsCh <- prepareCopyURLsTypeA(ctx, sourceURLs[0], targetURL, encKeyDB)
|
||||||
case copyURLsTypeB:
|
case copyURLsTypeB:
|
||||||
copyURLsCh <- prepareCopyURLsTypeB(sourceURLs[0], targetURL, encKeyDB)
|
copyURLsCh <- prepareCopyURLsTypeB(ctx, sourceURLs[0], targetURL, encKeyDB)
|
||||||
case copyURLsTypeC:
|
case copyURLsTypeC:
|
||||||
for cURLs := range prepareCopyURLsTypeC(sourceURLs[0], targetURL, isRecursive, encKeyDB) {
|
for cURLs := range prepareCopyURLsTypeC(ctx, sourceURLs[0], targetURL, isRecursive, encKeyDB) {
|
||||||
copyURLsCh <- cURLs
|
copyURLsCh <- cURLs
|
||||||
}
|
}
|
||||||
case copyURLsTypeD:
|
case copyURLsTypeD:
|
||||||
for cURLs := range prepareCopyURLsTypeD(sourceURLs, targetURL, isRecursive, encKeyDB) {
|
for cURLs := range prepareCopyURLsTypeD(ctx, sourceURLs, targetURL, isRecursive, encKeyDB) {
|
||||||
copyURLsCh <- cURLs
|
copyURLsCh <- cURLs
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
+21
-17
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ var diffCmd = cli.Command{
|
|||||||
Name: "diff",
|
Name: "diff",
|
||||||
Usage: "list differences in object name, size, and date between two buckets",
|
Usage: "list differences in object name, size, and date between two buckets",
|
||||||
Action: mainDiff,
|
Action: mainDiff,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(diffFlags, globalFlags...),
|
Flags: append(diffFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -90,7 +91,7 @@ func (d diffMessage) String() string {
|
|||||||
msg = console.Colorize("DiffSize", "! "+d.SecondURL)
|
msg = console.Colorize("DiffSize", "! "+d.SecondURL)
|
||||||
case differInMetadata:
|
case differInMetadata:
|
||||||
msg = console.Colorize("DiffMetadata", "! "+d.SecondURL)
|
msg = console.Colorize("DiffMetadata", "! "+d.SecondURL)
|
||||||
case differInMMSourceMTime:
|
case differInAASourceMTime:
|
||||||
msg = console.Colorize("DiffMMSourceMTime", "! "+d.SecondURL)
|
msg = console.Colorize("DiffMMSourceMTime", "! "+d.SecondURL)
|
||||||
default:
|
default:
|
||||||
fatalIf(errDummy().Trace(d.FirstURL, d.SecondURL),
|
fatalIf(errDummy().Trace(d.FirstURL, d.SecondURL),
|
||||||
@@ -109,23 +110,23 @@ func (d diffMessage) JSON() string {
|
|||||||
return string(diffJSONBytes)
|
return string(diffJSONBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkDiffSyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
func checkDiffSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
||||||
if len(ctx.Args()) != 2 {
|
if len(cliCtx.Args()) != 2 {
|
||||||
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(cliCtx, "diff", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
for _, arg := range ctx.Args() {
|
for _, arg := range cliCtx.Args() {
|
||||||
if strings.TrimSpace(arg) == "" {
|
if strings.TrimSpace(arg) == "" {
|
||||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "Unable to validate empty argument.")
|
fatalIf(errInvalidArgument().Trace(cliCtx.Args()...), "Unable to validate empty argument.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
URLs := ctx.Args()
|
URLs := cliCtx.Args()
|
||||||
firstURL := URLs[0]
|
firstURL := URLs[0]
|
||||||
secondURL := URLs[1]
|
secondURL := URLs[1]
|
||||||
|
|
||||||
// Diff only works between two directories, verify them below.
|
// Diff only works between two directories, verify them below.
|
||||||
|
|
||||||
// Verify if firstURL is accessible.
|
// Verify if firstURL is accessible.
|
||||||
_, firstContent, err := url2Stat(firstURL, false, encKeyDB)
|
_, firstContent, err := url2Stat(ctx, firstURL, false, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalIf(err.Trace(firstURL), fmt.Sprintf("Unable to stat '%s'.", firstURL))
|
fatalIf(err.Trace(firstURL), fmt.Sprintf("Unable to stat '%s'.", firstURL))
|
||||||
}
|
}
|
||||||
@@ -136,7 +137,7 @@ func checkDiffSyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify if secondURL is accessible.
|
// Verify if secondURL is accessible.
|
||||||
_, secondContent, err := url2Stat(secondURL, false, encKeyDB)
|
_, secondContent, err := url2Stat(ctx, secondURL, false, encKeyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalIf(err.Trace(secondURL), fmt.Sprintf("Unable to stat '%s'.", secondURL))
|
fatalIf(err.Trace(secondURL), fmt.Sprintf("Unable to stat '%s'.", secondURL))
|
||||||
}
|
}
|
||||||
@@ -148,7 +149,7 @@ func checkDiffSyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doDiffMain runs the diff.
|
// doDiffMain runs the diff.
|
||||||
func doDiffMain(firstURL, secondURL string) error {
|
func doDiffMain(ctx context.Context, firstURL, secondURL string) error {
|
||||||
// Source and targets are always directories
|
// Source and targets are always directories
|
||||||
sourceSeparator := string(newClientURL(firstURL).Separator)
|
sourceSeparator := string(newClientURL(firstURL).Separator)
|
||||||
if !strings.HasSuffix(firstURL, sourceSeparator) {
|
if !strings.HasSuffix(firstURL, sourceSeparator) {
|
||||||
@@ -176,7 +177,7 @@ func doDiffMain(firstURL, secondURL string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Diff first and second urls.
|
// Diff first and second urls.
|
||||||
for diffMsg := range objectDifference(firstClient, secondClient, firstURL, secondURL, false) {
|
for diffMsg := range objectDifference(ctx, firstClient, secondClient, firstURL, secondURL, true) {
|
||||||
if diffMsg.Error != nil {
|
if diffMsg.Error != nil {
|
||||||
errorIf(diffMsg.Error, "Unable to calculate objects difference.")
|
errorIf(diffMsg.Error, "Unable to calculate objects difference.")
|
||||||
// Ignore error and proceed to next object.
|
// Ignore error and proceed to next object.
|
||||||
@@ -189,13 +190,16 @@ func doDiffMain(firstURL, secondURL string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mainDiff main for 'diff'.
|
// mainDiff main for 'diff'.
|
||||||
func mainDiff(ctx *cli.Context) error {
|
func mainDiff(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelDiff := context.WithCancel(globalContext)
|
||||||
|
defer cancelDiff()
|
||||||
|
|
||||||
// Parse encryption keys per command.
|
// Parse encryption keys per command.
|
||||||
encKeyDB, err := getEncKeys(ctx)
|
encKeyDB, err := getEncKeys(cliCtx)
|
||||||
fatalIf(err, "Unable to parse encryption keys.")
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
|
|
||||||
// check 'diff' cli arguments.
|
// check 'diff' cli arguments.
|
||||||
checkDiffSyntax(ctx, encKeyDB)
|
checkDiffSyntax(ctx, cliCtx, encKeyDB)
|
||||||
|
|
||||||
// Additional command specific theme customization.
|
// Additional command specific theme customization.
|
||||||
console.SetColor("DiffMessage", color.New(color.FgGreen, color.Bold))
|
console.SetColor("DiffMessage", color.New(color.FgGreen, color.Bold))
|
||||||
@@ -206,9 +210,9 @@ func mainDiff(ctx *cli.Context) error {
|
|||||||
console.SetColor("DiffMetadata", color.New(color.FgYellow, color.Bold))
|
console.SetColor("DiffMetadata", color.New(color.FgYellow, color.Bold))
|
||||||
console.SetColor("DiffMMSourceMTime", color.New(color.FgYellow, color.Bold))
|
console.SetColor("DiffMMSourceMTime", color.New(color.FgYellow, color.Bold))
|
||||||
|
|
||||||
URLs := ctx.Args()
|
URLs := cliCtx.Args()
|
||||||
firstURL := URLs.Get(0)
|
firstURL := URLs.Get(0)
|
||||||
secondURL := URLs.Get(1)
|
secondURL := URLs.Get(1)
|
||||||
|
|
||||||
return doDiffMain(firstURL, secondURL)
|
return doDiffMain(ctx, firstURL, secondURL)
|
||||||
}
|
}
|
||||||
|
|||||||
+68
-38
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -38,7 +39,7 @@ const (
|
|||||||
differInType // differs in type, exfile/directory
|
differInType // differs in type, exfile/directory
|
||||||
differInFirst // only in source (FIRST)
|
differInFirst // only in source (FIRST)
|
||||||
differInSecond // only in target (SECOND)
|
differInSecond // only in target (SECOND)
|
||||||
differInMMSourceMTime // differs in multi-master source modtime
|
differInAASourceMTime // differs in active-active source modtime
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d differType) String() string {
|
func (d differType) String() string {
|
||||||
@@ -49,7 +50,7 @@ func (d differType) String() string {
|
|||||||
return "size"
|
return "size"
|
||||||
case differInMetadata:
|
case differInMetadata:
|
||||||
return "metadata"
|
return "metadata"
|
||||||
case differInMMSourceMTime:
|
case differInAASourceMTime:
|
||||||
return "mm-source-mtime"
|
return "mm-source-mtime"
|
||||||
case differInType:
|
case differInType:
|
||||||
return "type"
|
return "type"
|
||||||
@@ -61,25 +62,27 @@ func (d differType) String() string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
const multiMasterSourceModTimeKey = "X-Amz-Meta-Mm-Source-Mtime"
|
const activeActiveSourceModTimeKey = "X-Amz-Meta-Mm-Source-Mtime"
|
||||||
|
|
||||||
func oldestNonNullTime(t1, t2 time.Time) time.Time {
|
func getSourceModTimeKey(metadata map[string]string) string {
|
||||||
if t1.IsZero() {
|
if metadata[activeActiveSourceModTimeKey] != "" {
|
||||||
return t2
|
return metadata[activeActiveSourceModTimeKey]
|
||||||
}
|
}
|
||||||
if t2.IsZero() {
|
if metadata[strings.ToLower(activeActiveSourceModTimeKey)] != "" {
|
||||||
return t1
|
return metadata[strings.ToLower(activeActiveSourceModTimeKey)]
|
||||||
}
|
}
|
||||||
if t1.Before(t2) {
|
if metadata[strings.ToLower("Mm-Source-Mtime")] != "" {
|
||||||
return t1
|
return metadata[strings.ToLower("Mm-Source-Mtime")]
|
||||||
}
|
}
|
||||||
|
if metadata["Mm-Source-Mtime"] != "" {
|
||||||
return t2
|
return metadata["Mm-Source-Mtime"]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiMasterModTimeUpdated tries to calculate if the object copy in the target
|
// activeActiveModTimeUpdated tries to calculate if the object copy in the target
|
||||||
// is older than the one in the source by comparing the modtime of the data.
|
// is older than the one in the source by comparing the modtime of the data.
|
||||||
func multiMasterModTimeUpdated(src, dst *ClientContent) bool {
|
func activeActiveModTimeUpdated(src, dst *ClientContent) bool {
|
||||||
if src == nil || dst == nil {
|
if src == nil || dst == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -91,25 +94,49 @@ func multiMasterModTimeUpdated(src, dst *ClientContent) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok1 := src.UserMetadata[multiMasterSourceModTimeKey]
|
srcModTime := getSourceModTimeKey(src.UserMetadata)
|
||||||
_, ok2 := dst.UserMetadata[multiMasterSourceModTimeKey]
|
dstModTime := getSourceModTimeKey(dst.UserMetadata)
|
||||||
if !ok1 && !ok2 {
|
if srcModTime == "" && dstModTime == "" {
|
||||||
// No multimaster context found, consider src & dst as similar
|
// No active-active mirror context found, consider src & dst as similar
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
srcOriginLastModified, _ := time.Parse(time.RFC3339Nano, src.UserMetadata[multiMasterSourceModTimeKey])
|
var srcOriginLastModified, dstOriginLastModified time.Time
|
||||||
dstOriginLastModified, _ := time.Parse(time.RFC3339Nano, dst.UserMetadata[multiMasterSourceModTimeKey])
|
var err error
|
||||||
|
if srcModTime != "" {
|
||||||
|
srcOriginLastModified, err = time.Parse(time.RFC3339Nano, srcModTime)
|
||||||
|
if err != nil {
|
||||||
|
// failure to parse source modTime, modTime tampered ignore the file
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if dstModTime != "" {
|
||||||
|
dstOriginLastModified, err = time.Parse(time.RFC3339Nano, dstModTime)
|
||||||
|
if err != nil {
|
||||||
|
// failure to parse source modTime, modTime tampered ignore the file
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
srcActualModTime := oldestNonNullTime(src.Time, srcOriginLastModified)
|
srcActualModTime := src.Time
|
||||||
dstActualModTime := oldestNonNullTime(dst.Time, dstOriginLastModified)
|
if !srcOriginLastModified.IsZero() && srcOriginLastModified.After(src.Time) {
|
||||||
|
srcActualModTime = srcOriginLastModified
|
||||||
|
}
|
||||||
|
|
||||||
|
dstActualModTime := dst.Time
|
||||||
|
if !dstOriginLastModified.IsZero() && dstOriginLastModified.After(dst.Time) {
|
||||||
|
dstActualModTime = dstOriginLastModified
|
||||||
|
}
|
||||||
|
|
||||||
return srcActualModTime.After(dstActualModTime)
|
return srcActualModTime.After(dstActualModTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataEqual(m1, m2 map[string]string) bool {
|
func metadataEqual(m1, m2 map[string]string) bool {
|
||||||
for k, v := range m1 {
|
for k, v := range m1 {
|
||||||
if k == multiMasterSourceModTimeKey {
|
if k == activeActiveSourceModTimeKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if k == strings.ToLower(activeActiveSourceModTimeKey) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if m2[k] != v {
|
if m2[k] != v {
|
||||||
@@ -117,7 +144,10 @@ func metadataEqual(m1, m2 map[string]string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k, v := range m2 {
|
for k, v := range m2 {
|
||||||
if k == multiMasterSourceModTimeKey {
|
if k == activeActiveSourceModTimeKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if k == strings.ToLower(activeActiveSourceModTimeKey) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if m1[k] != v {
|
if m1[k] != v {
|
||||||
@@ -127,19 +157,19 @@ func metadataEqual(m1, m2 map[string]string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectDifference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool) (diffCh chan diffMessage) {
|
func objectDifference(ctx context.Context, sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool) (diffCh chan diffMessage) {
|
||||||
return difference(sourceClnt, targetClnt, sourceURL, targetURL, isMetadata, true, false, DirNone)
|
return difference(ctx, sourceClnt, targetClnt, sourceURL, targetURL, isMetadata, true, false, DirNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dirDifference(sourceClnt, targetClnt Client, sourceURL, targetURL string) (diffCh chan diffMessage) {
|
func dirDifference(ctx context.Context, sourceClnt, targetClnt Client, sourceURL, targetURL string) (diffCh chan diffMessage) {
|
||||||
return difference(sourceClnt, targetClnt, sourceURL, targetURL, false, false, true, DirFirst)
|
return difference(ctx, sourceClnt, targetClnt, sourceURL, targetURL, false, false, true, DirFirst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func differenceInternal(sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool, isRecursive, returnSimilar bool, dirOpt DirOpt, diffCh chan<- diffMessage) *probe.Error {
|
func differenceInternal(ctx context.Context, sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool, isRecursive, returnSimilar bool, dirOpt DirOpt, diffCh chan<- diffMessage) *probe.Error {
|
||||||
// Set default values for listing.
|
// Set default values for listing.
|
||||||
isIncomplete := false // we will not compare any incomplete objects.
|
isIncomplete := false // we will not compare any incomplete objects.
|
||||||
srcCh := sourceClnt.List(isRecursive, isIncomplete, isMetadata, dirOpt)
|
srcCh := sourceClnt.List(ctx, isRecursive, isIncomplete, isMetadata, dirOpt)
|
||||||
tgtCh := targetClnt.List(isRecursive, isIncomplete, isMetadata, dirOpt)
|
tgtCh := targetClnt.List(ctx, isRecursive, isIncomplete, isMetadata, dirOpt)
|
||||||
|
|
||||||
srcCtnt, srcOk := <-srcCh
|
srcCtnt, srcOk := <-srcCh
|
||||||
tgtCtnt, tgtOk := <-tgtCh
|
tgtCtnt, tgtOk := <-tgtCh
|
||||||
@@ -245,11 +275,11 @@ func differenceInternal(sourceClnt, targetClnt Client, sourceURL, targetURL stri
|
|||||||
firstContent: srcCtnt,
|
firstContent: srcCtnt,
|
||||||
secondContent: tgtCtnt,
|
secondContent: tgtCtnt,
|
||||||
}
|
}
|
||||||
} else if multiMasterModTimeUpdated(srcCtnt, tgtCtnt) {
|
} else if activeActiveModTimeUpdated(srcCtnt, tgtCtnt) {
|
||||||
diffCh <- diffMessage{
|
diffCh <- diffMessage{
|
||||||
FirstURL: srcCtnt.URL.String(),
|
FirstURL: srcCtnt.URL.String(),
|
||||||
SecondURL: tgtCtnt.URL.String(),
|
SecondURL: tgtCtnt.URL.String(),
|
||||||
Diff: differInMMSourceMTime,
|
Diff: differInAASourceMTime,
|
||||||
firstContent: srcCtnt,
|
firstContent: srcCtnt,
|
||||||
secondContent: tgtCtnt,
|
secondContent: tgtCtnt,
|
||||||
}
|
}
|
||||||
@@ -296,17 +326,17 @@ func differenceInternal(sourceClnt, targetClnt Client, sourceURL, targetURL stri
|
|||||||
|
|
||||||
// objectDifference function finds the difference between all objects
|
// objectDifference function finds the difference between all objects
|
||||||
// recursively in sorted order from source and target.
|
// recursively in sorted order from source and target.
|
||||||
func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool, isRecursive, returnSimilar bool, dirOpt DirOpt) (diffCh chan diffMessage) {
|
func difference(ctx context.Context, sourceClnt, targetClnt Client, sourceURL, targetURL string, isMetadata bool, isRecursive, returnSimilar bool, dirOpt DirOpt) (diffCh chan diffMessage) {
|
||||||
diffCh = make(chan diffMessage, 10000)
|
diffCh = make(chan diffMessage, 10000)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(diffCh)
|
defer close(diffCh)
|
||||||
|
|
||||||
doneCh := make(chan struct{}, 1)
|
retryCtx, cancel := context.WithCancel(ctx)
|
||||||
defer close(doneCh)
|
defer cancel()
|
||||||
|
|
||||||
for range newRetryTimerContinous(time.Second, time.Second*30, minio.MaxJitter, doneCh) {
|
for range newRetryTimerContinous(retryCtx, time.Second, time.Second*30, minio.MaxJitter) {
|
||||||
err := differenceInternal(sourceClnt, targetClnt, sourceURL, targetURL,
|
err := differenceInternal(retryCtx, sourceClnt, targetClnt, sourceURL, targetURL,
|
||||||
isMetadata, isRecursive, returnSimilar, dirOpt, diffCh)
|
isMetadata, isRecursive, returnSimilar, dirOpt, diffCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle this specifically for filesystem related errors.
|
// handle this specifically for filesystem related errors.
|
||||||
|
|||||||
+2
-2
@@ -48,7 +48,7 @@ var duCmd = cli.Command{
|
|||||||
Name: "du",
|
Name: "du",
|
||||||
Usage: "summarize disk usage recursively",
|
Usage: "summarize disk usage recursively",
|
||||||
Action: mainDu,
|
Action: mainDu,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(append(duFlags, ioFlags...), globalFlags...),
|
Flags: append(append(duFlags, ioFlags...), globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -107,7 +107,7 @@ func du(urlStr string, depth int, encKeyDB map[string][]prefixSSEPair) (int64, e
|
|||||||
|
|
||||||
isRecursive := false
|
isRecursive := false
|
||||||
isIncomplete := false
|
isIncomplete := false
|
||||||
contentCh := clnt.List(isRecursive, isIncomplete, false, DirFirst)
|
contentCh := clnt.List(globalContext, isRecursive, isIncomplete, false, DirFirst)
|
||||||
size := int64(0)
|
size := int64(0)
|
||||||
for content := range contentCh {
|
for content := range contentCh {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
|
|||||||
+13
-9
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@@ -52,7 +53,7 @@ var eventAddCmd = cli.Command{
|
|||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "add a new bucket notification",
|
Usage: "add a new bucket notification",
|
||||||
Action: mainEventAdd,
|
Action: mainEventAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(eventAddFlags, globalFlags...),
|
Flags: append(eventAddFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -104,19 +105,22 @@ func (u eventAddMessage) String() string {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainEventAdd(ctx *cli.Context) error {
|
func mainEventAdd(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelEventAdd := context.WithCancel(globalContext)
|
||||||
|
defer cancelEventAdd()
|
||||||
|
|
||||||
console.SetColor("Event", color.New(color.FgGreen, color.Bold))
|
console.SetColor("Event", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
checkEventAddSyntax(ctx)
|
checkEventAddSyntax(cliCtx)
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
path := args[0]
|
path := args[0]
|
||||||
arn := args[1]
|
arn := args[1]
|
||||||
ignoreExisting := ctx.Bool("p")
|
ignoreExisting := cliCtx.Bool("p")
|
||||||
|
|
||||||
event := strings.Split(ctx.String("event"), ",")
|
event := strings.Split(cliCtx.String("event"), ",")
|
||||||
prefix := ctx.String("prefix")
|
prefix := cliCtx.String("prefix")
|
||||||
suffix := ctx.String("suffix")
|
suffix := cliCtx.String("suffix")
|
||||||
|
|
||||||
client, err := newClient(path)
|
client, err := newClient(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,7 +132,7 @@ func mainEventAdd(ctx *cli.Context) error {
|
|||||||
fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
|
fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s3Client.AddNotificationConfig(arn, event, prefix, suffix, ignoreExisting)
|
err = s3Client.AddNotificationConfig(ctx, arn, event, prefix, suffix, ignoreExisting)
|
||||||
fatalIf(err, "Cannot enable notification on the specified bucket.")
|
fatalIf(err, "Cannot enable notification on the specified bucket.")
|
||||||
printMsg(eventAddMessage{
|
printMsg(eventAddMessage{
|
||||||
ARN: arn,
|
ARN: arn,
|
||||||
|
|||||||
+9
-5
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@@ -34,7 +35,7 @@ var eventListCmd = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "list bucket notifications",
|
Usage: "list bucket notifications",
|
||||||
Action: mainEventList,
|
Action: mainEventList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(eventListFlags, globalFlags...),
|
Flags: append(eventListFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -96,14 +97,17 @@ func (u eventListMessage) String() string {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainEventList(ctx *cli.Context) error {
|
func mainEventList(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelEventList := context.WithCancel(globalContext)
|
||||||
|
defer cancelEventList()
|
||||||
|
|
||||||
console.SetColor("ARN", color.New(color.FgGreen, color.Bold))
|
console.SetColor("ARN", color.New(color.FgGreen, color.Bold))
|
||||||
console.SetColor("Event", color.New(color.FgCyan, color.Bold))
|
console.SetColor("Event", color.New(color.FgCyan, color.Bold))
|
||||||
console.SetColor("Filter", color.New(color.Bold))
|
console.SetColor("Filter", color.New(color.Bold))
|
||||||
|
|
||||||
checkEventListSyntax(ctx)
|
checkEventListSyntax(cliCtx)
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
path := args[0]
|
path := args[0]
|
||||||
arn := ""
|
arn := ""
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
@@ -120,7 +124,7 @@ func mainEventList(ctx *cli.Context) error {
|
|||||||
fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
|
fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
|
||||||
}
|
}
|
||||||
|
|
||||||
configs, err := s3Client.ListNotificationConfigs(arn)
|
configs, err := s3Client.ListNotificationConfigs(ctx, arn)
|
||||||
fatalIf(err, "Cannot list notifications on the specified bucket.")
|
fatalIf(err, "Cannot list notifications on the specified bucket.")
|
||||||
|
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ var eventCmd = cli.Command{
|
|||||||
Usage: "configure object notifications",
|
Usage: "configure object notifications",
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Action: mainEvent,
|
Action: mainEvent,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: append(eventFlags, globalFlags...),
|
Flags: append(eventFlags, globalFlags...),
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
eventAddCmd,
|
eventAddCmd,
|
||||||
|
|||||||
+12
-8
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v6"
|
"github.com/minio/minio-go/v6"
|
||||||
@@ -53,7 +54,7 @@ var eventRemoveCmd = cli.Command{
|
|||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove a bucket notification; '--force' removes all bucket notifications",
|
Usage: "remove a bucket notification; '--force' removes all bucket notifications",
|
||||||
Action: mainEventRemove,
|
Action: mainEventRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(eventRemoveFlags, globalFlags...),
|
Flags: append(eventRemoveFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -102,12 +103,15 @@ func (u eventRemoveMessage) String() string {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainEventRemove(ctx *cli.Context) error {
|
func mainEventRemove(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelEventRemove := context.WithCancel(globalContext)
|
||||||
|
defer cancelEventRemove()
|
||||||
|
|
||||||
console.SetColor("Event", color.New(color.FgGreen, color.Bold))
|
console.SetColor("Event", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
checkEventRemoveSyntax(ctx)
|
checkEventRemoveSyntax(cliCtx)
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
path := args.Get(0)
|
path := args.Get(0)
|
||||||
|
|
||||||
arn := ""
|
arn := ""
|
||||||
@@ -126,11 +130,11 @@ func mainEventRemove(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flags for the attributes of the even
|
// flags for the attributes of the even
|
||||||
event := ctx.String("event")
|
event := cliCtx.String("event")
|
||||||
prefix := ctx.String("prefix")
|
prefix := cliCtx.String("prefix")
|
||||||
suffix := ctx.String("suffix")
|
suffix := cliCtx.String("suffix")
|
||||||
|
|
||||||
err = s3Client.RemoveNotificationConfig(arn, event, prefix, suffix)
|
err = s3Client.RemoveNotificationConfig(ctx, arn, event, prefix, suffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Cause == minio.ErrNoNotificationConfigMatch {
|
if err.Cause == minio.ErrNoNotificationConfigMatch {
|
||||||
fatalIf(err, "Remove event failed.")
|
fatalIf(err, "Remove event failed.")
|
||||||
|
|||||||
+33
-29
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
humanize "github.com/dustin/go-humanize"
|
humanize "github.com/dustin/go-humanize"
|
||||||
@@ -84,7 +85,7 @@ var findCmd = cli.Command{
|
|||||||
Name: "find",
|
Name: "find",
|
||||||
Usage: "search for objects",
|
Usage: "search for objects",
|
||||||
Action: mainFind,
|
Action: mainFind,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(findFlags, globalFlags...),
|
Flags: append(findFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -154,8 +155,8 @@ EXAMPLES:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkFindSyntax - validate the passed arguments
|
// checkFindSyntax - validate the passed arguments
|
||||||
func checkFindSyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
func checkFindSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
if !args.Present() {
|
if !args.Present() {
|
||||||
args = []string{"./"} // No args just default to present directory.
|
args = []string{"./"} // No args just default to present directory.
|
||||||
} else if args.Get(0) == "." {
|
} else if args.Get(0) == "." {
|
||||||
@@ -170,10 +171,10 @@ func checkFindSyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) {
|
|||||||
|
|
||||||
// Extract input URLs and validate.
|
// Extract input URLs and validate.
|
||||||
for _, url := range args {
|
for _, url := range args {
|
||||||
_, _, err := url2Stat(url, false, encKeyDB)
|
_, _, err := url2Stat(ctx, url, false, encKeyDB)
|
||||||
if err != nil && !isURLPrefixExists(url, false) {
|
if err != nil && !isURLPrefixExists(url, false) {
|
||||||
// Bucket name empty is a valid error for 'find myminio' unless we are using watch, treat it as such.
|
// Bucket name empty is a valid error for 'find myminio' unless we are using watch, treat it as such.
|
||||||
if _, ok := err.ToGoError().(BucketNameEmpty); ok && !ctx.Bool("watch") {
|
if _, ok := err.ToGoError().(BucketNameEmpty); ok && !cliCtx.Bool("watch") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fatalIf(err.Trace(url), "Unable to stat `"+url+"`.")
|
fatalIf(err.Trace(url), "Unable to stat `"+url+"`.")
|
||||||
@@ -207,18 +208,21 @@ type findContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mainFind - handler for mc find commands
|
// mainFind - handler for mc find commands
|
||||||
func mainFind(ctx *cli.Context) error {
|
func mainFind(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelFind := context.WithCancel(globalContext)
|
||||||
|
defer cancelFind()
|
||||||
|
|
||||||
// Additional command specific theme customization.
|
// Additional command specific theme customization.
|
||||||
console.SetColor("Find", color.New(color.FgGreen, color.Bold))
|
console.SetColor("Find", color.New(color.FgGreen, color.Bold))
|
||||||
console.SetColor("FindExecErr", color.New(color.FgRed, color.Italic, color.Bold))
|
console.SetColor("FindExecErr", color.New(color.FgRed, color.Italic, color.Bold))
|
||||||
|
|
||||||
// Parse encryption keys per command.
|
// Parse encryption keys per command.
|
||||||
encKeyDB, err := getEncKeys(ctx)
|
encKeyDB, err := getEncKeys(cliCtx)
|
||||||
fatalIf(err, "Unable to parse encryption keys.")
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
|
|
||||||
checkFindSyntax(ctx, encKeyDB)
|
checkFindSyntax(ctx, cliCtx, encKeyDB)
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
if !args.Present() {
|
if !args.Present() {
|
||||||
args = []string{"./"} // Not args present default to present directory.
|
args = []string{"./"} // Not args present default to present directory.
|
||||||
} else if args.Get(0) == "." {
|
} else if args.Get(0) == "." {
|
||||||
@@ -230,11 +234,11 @@ func mainFind(ctx *cli.Context) error {
|
|||||||
|
|
||||||
var olderThan, newerThan string
|
var olderThan, newerThan string
|
||||||
|
|
||||||
if ctx.String("older-than") != "" {
|
if cliCtx.String("older-than") != "" {
|
||||||
olderThan = ctx.String("older-than")
|
olderThan = cliCtx.String("older-than")
|
||||||
}
|
}
|
||||||
if ctx.String("newer-than") != "" {
|
if cliCtx.String("newer-than") != "" {
|
||||||
newerThan = ctx.String("newer-than")
|
newerThan = cliCtx.String("newer-than")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use 'e' to indicate Go error, this is a convention followed in `mc`. For probe.Error we call it
|
// Use 'e' to indicate Go error, this is a convention followed in `mc`. For probe.Error we call it
|
||||||
@@ -242,14 +246,14 @@ func mainFind(ctx *cli.Context) error {
|
|||||||
var e error
|
var e error
|
||||||
var largerSize, smallerSize uint64
|
var largerSize, smallerSize uint64
|
||||||
|
|
||||||
if ctx.String("larger") != "" {
|
if cliCtx.String("larger") != "" {
|
||||||
largerSize, e = humanize.ParseBytes(ctx.String("larger"))
|
largerSize, e = humanize.ParseBytes(cliCtx.String("larger"))
|
||||||
fatalIf(probe.NewError(e).Trace(ctx.String("larger")), "Unable to parse input bytes.")
|
fatalIf(probe.NewError(e).Trace(cliCtx.String("larger")), "Unable to parse input bytes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.String("smaller") != "" {
|
if cliCtx.String("smaller") != "" {
|
||||||
smallerSize, e = humanize.ParseBytes(ctx.String("smaller"))
|
smallerSize, e = humanize.ParseBytes(cliCtx.String("smaller"))
|
||||||
fatalIf(probe.NewError(e).Trace(ctx.String("smaller")), "Unable to parse input bytes.")
|
fatalIf(probe.NewError(e).Trace(cliCtx.String("smaller")), "Unable to parse input bytes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
targetAlias, _, hostCfg, err := expandAlias(args[0])
|
targetAlias, _, hostCfg, err := expandAlias(args[0])
|
||||||
@@ -260,20 +264,20 @@ func mainFind(ctx *cli.Context) error {
|
|||||||
targetFullURL = hostCfg.URL
|
targetFullURL = hostCfg.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
return doFind(&findContext{
|
return doFind(ctx, &findContext{
|
||||||
Context: ctx,
|
Context: cliCtx,
|
||||||
maxDepth: ctx.Uint("maxdepth"),
|
maxDepth: cliCtx.Uint("maxdepth"),
|
||||||
execCmd: ctx.String("exec"),
|
execCmd: cliCtx.String("exec"),
|
||||||
printFmt: ctx.String("print"),
|
printFmt: cliCtx.String("print"),
|
||||||
namePattern: ctx.String("name"),
|
namePattern: cliCtx.String("name"),
|
||||||
pathPattern: ctx.String("path"),
|
pathPattern: cliCtx.String("path"),
|
||||||
regexPattern: ctx.String("regex"),
|
regexPattern: cliCtx.String("regex"),
|
||||||
ignorePattern: ctx.String("ignore"),
|
ignorePattern: cliCtx.String("ignore"),
|
||||||
olderThan: olderThan,
|
olderThan: olderThan,
|
||||||
newerThan: newerThan,
|
newerThan: newerThan,
|
||||||
largerSize: largerSize,
|
largerSize: largerSize,
|
||||||
smallerSize: smallerSize,
|
smallerSize: smallerSize,
|
||||||
watch: ctx.Bool("watch"),
|
watch: cliCtx.Bool("watch"),
|
||||||
targetAlias: targetAlias,
|
targetAlias: targetAlias,
|
||||||
targetURL: args[0],
|
targetURL: args[0],
|
||||||
targetFullURL: targetFullURL,
|
targetFullURL: targetFullURL,
|
||||||
|
|||||||
+18
-17
@@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -131,7 +132,7 @@ func execFind(command string) {
|
|||||||
// watchFind - enables listening on the input path, listens for all file/object
|
// watchFind - enables listening on the input path, listens for all file/object
|
||||||
// created actions. Asynchronously executes the input command line, also allows
|
// created actions. Asynchronously executes the input command line, also allows
|
||||||
// formatting for the command line in accordance with subsititution arguments.
|
// formatting for the command line in accordance with subsititution arguments.
|
||||||
func watchFind(ctx *findContext) {
|
func watchFind(ctxCtx context.Context, ctx *findContext) {
|
||||||
// Watch is not enabled, return quickly.
|
// Watch is not enabled, return quickly.
|
||||||
if !ctx.watch {
|
if !ctx.watch {
|
||||||
return
|
return
|
||||||
@@ -140,7 +141,7 @@ func watchFind(ctx *findContext) {
|
|||||||
Recursive: true,
|
Recursive: true,
|
||||||
Events: []string{"put"},
|
Events: []string{"put"},
|
||||||
}
|
}
|
||||||
watchObj, err := ctx.clnt.Watch(options)
|
watchObj, err := ctx.clnt.Watch(ctxCtx, options)
|
||||||
fatalIf(err.Trace(ctx.targetAlias), "Cannot watch with given options.")
|
fatalIf(err.Trace(ctx.targetAlias), "Cannot watch with given options.")
|
||||||
|
|
||||||
// Loop until user CTRL-C the command line.
|
// Loop until user CTRL-C the command line.
|
||||||
@@ -162,7 +163,7 @@ func watchFind(ctx *findContext) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
find(ctx, contentMessage{
|
find(ctxCtx, ctx, contentMessage{
|
||||||
Key: getAliasedPath(ctx, event.Path),
|
Key: getAliasedPath(ctx, event.Path),
|
||||||
Time: time,
|
Time: time,
|
||||||
Size: event.Size,
|
Size: event.Size,
|
||||||
@@ -220,7 +221,7 @@ func getAliasedPath(ctx *findContext, path string) string {
|
|||||||
return trimSuffixAtMaxDepth(ctx.targetURL, aliasedPath, separator, ctx.maxDepth)
|
return trimSuffixAtMaxDepth(ctx.targetURL, aliasedPath, separator, ctx.maxDepth)
|
||||||
}
|
}
|
||||||
|
|
||||||
func find(ctx *findContext, fileContent contentMessage) {
|
func find(ctxCtx context.Context, ctx *findContext, fileContent contentMessage) {
|
||||||
// Match the incoming content, didn't match return.
|
// Match the incoming content, didn't match return.
|
||||||
if !matchFind(ctx, fileContent) {
|
if !matchFind(ctx, fileContent) {
|
||||||
return
|
return
|
||||||
@@ -228,27 +229,27 @@ func find(ctx *findContext, fileContent contentMessage) {
|
|||||||
|
|
||||||
// proceed to either exec, format the output string.
|
// proceed to either exec, format the output string.
|
||||||
if ctx.execCmd != "" {
|
if ctx.execCmd != "" {
|
||||||
execFind(stringsReplace(ctx.execCmd, fileContent))
|
execFind(stringsReplace(ctxCtx, ctx.execCmd, fileContent))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.printFmt != "" {
|
if ctx.printFmt != "" {
|
||||||
fileContent.Key = stringsReplace(ctx.printFmt, fileContent)
|
fileContent.Key = stringsReplace(ctxCtx, ctx.printFmt, fileContent)
|
||||||
}
|
}
|
||||||
printMsg(findMessage{fileContent})
|
printMsg(findMessage{fileContent})
|
||||||
}
|
}
|
||||||
|
|
||||||
// doFind - find is main function body which interprets and executes
|
// doFind - find is main function body which interprets and executes
|
||||||
// all the input parameters.
|
// all the input parameters.
|
||||||
func doFind(ctx *findContext) error {
|
func doFind(ctxCtx context.Context, ctx *findContext) error {
|
||||||
// If watch is enabled we will wait on the prefix perpetually
|
// If watch is enabled we will wait on the prefix perpetually
|
||||||
// for all I/O events until canceled by user, if watch is not enabled
|
// for all I/O events until canceled by user, if watch is not enabled
|
||||||
// following defer is a no-op.
|
// following defer is a no-op.
|
||||||
defer watchFind(ctx)
|
defer watchFind(ctxCtx, ctx)
|
||||||
|
|
||||||
var prevKeyName string
|
var prevKeyName string
|
||||||
|
|
||||||
// iterate over all content which is within the given directory
|
// iterate over all content which is within the given directory
|
||||||
for content := range ctx.clnt.List(true, false, false, DirNone) {
|
for content := range ctx.clnt.List(globalContext, true, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
switch content.Err.ToGoError().(type) {
|
switch content.Err.ToGoError().(type) {
|
||||||
// handle this specifically for filesystem related errors.
|
// handle this specifically for filesystem related errors.
|
||||||
@@ -288,11 +289,11 @@ func doFind(ctx *findContext) error {
|
|||||||
|
|
||||||
// proceed to either exec, format the output string.
|
// proceed to either exec, format the output string.
|
||||||
if ctx.execCmd != "" {
|
if ctx.execCmd != "" {
|
||||||
execFind(stringsReplace(ctx.execCmd, fileContent))
|
execFind(stringsReplace(ctxCtx, ctx.execCmd, fileContent))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ctx.printFmt != "" {
|
if ctx.printFmt != "" {
|
||||||
fileContent.Key = stringsReplace(ctx.printFmt, fileContent)
|
fileContent.Key = stringsReplace(ctxCtx, ctx.printFmt, fileContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
printMsg(findMessage{fileContent})
|
printMsg(findMessage{fileContent})
|
||||||
@@ -305,7 +306,7 @@ func doFind(ctx *findContext) error {
|
|||||||
|
|
||||||
// stringsReplace - formats the string to remove {} and replace each
|
// stringsReplace - formats the string to remove {} and replace each
|
||||||
// with the appropriate argument
|
// with the appropriate argument
|
||||||
func stringsReplace(args string, fileContent contentMessage) string {
|
func stringsReplace(ctx context.Context, args string, fileContent contentMessage) string {
|
||||||
// replace all instances of {}
|
// replace all instances of {}
|
||||||
str := args
|
str := args
|
||||||
if strings.Contains(str, "{}") {
|
if strings.Contains(str, "{}") {
|
||||||
@@ -359,12 +360,12 @@ func stringsReplace(args string, fileContent contentMessage) string {
|
|||||||
|
|
||||||
// replace all instances of {url}
|
// replace all instances of {url}
|
||||||
if strings.Contains(str, "{url}") {
|
if strings.Contains(str, "{url}") {
|
||||||
str = strings.Replace(str, "{url}", getShareURL(fileContent.Key), -1)
|
str = strings.Replace(str, "{url}", getShareURL(ctx, fileContent.Key), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace all instances of {"url"}
|
// replace all instances of {"url"}
|
||||||
if strings.Contains(str, `{"url"}`) {
|
if strings.Contains(str, `{"url"}`) {
|
||||||
str = strings.Replace(str, `{"url"}`, strconv.Quote(getShareURL(fileContent.Key)), -1)
|
str = strings.Replace(str, `{"url"}`, strconv.Quote(getShareURL(ctx, fileContent.Key)), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
@@ -414,14 +415,14 @@ var defaultSevenDays = time.Duration(604800) * time.Second
|
|||||||
|
|
||||||
// getShareURL is used in conjunction with the {url} substitution
|
// getShareURL is used in conjunction with the {url} substitution
|
||||||
// argument to generate and return presigned URLs, returns error if any.
|
// argument to generate and return presigned URLs, returns error if any.
|
||||||
func getShareURL(path string) string {
|
func getShareURL(ctx context.Context, path string) string {
|
||||||
targetAlias, targetURLFull, _, err := expandAlias(path)
|
targetAlias, targetURLFull, _, err := expandAlias(path)
|
||||||
fatalIf(err.Trace(path), "Unable to expand alias.")
|
fatalIf(err.Trace(path), "Unable to expand alias.")
|
||||||
|
|
||||||
clnt, err := newClientFromAlias(targetAlias, targetURLFull)
|
clnt, err := newClientFromAlias(targetAlias, targetURLFull)
|
||||||
fatalIf(err.Trace(targetAlias, targetURLFull), "Unable to initialize client instance from alias.")
|
fatalIf(err.Trace(targetAlias, targetURLFull), "Unable to initialize client instance from alias.")
|
||||||
|
|
||||||
content, err := clnt.Stat(false, false, nil)
|
content, err := clnt.Stat(ctx, false, false, nil)
|
||||||
fatalIf(err.Trace(targetURLFull, targetAlias), "Unable to lookup file/object.")
|
fatalIf(err.Trace(targetURLFull, targetAlias), "Unable to lookup file/object.")
|
||||||
|
|
||||||
// Skip if its a directory.
|
// Skip if its a directory.
|
||||||
@@ -434,7 +435,7 @@ func getShareURL(path string) string {
|
|||||||
fatalIf(err.Trace(targetAlias, objectURL), "Unable to initialize new client from alias.")
|
fatalIf(err.Trace(targetAlias, objectURL), "Unable to initialize new client from alias.")
|
||||||
|
|
||||||
// Set default expiry for each url (point of no longer valid), to be 7 days
|
// Set default expiry for each url (point of no longer valid), to be 7 days
|
||||||
shareURL, err := newClnt.ShareDownload(defaultSevenDays)
|
shareURL, err := newClnt.ShareDownload(ctx, defaultSevenDays)
|
||||||
fatalIf(err.Trace(targetAlias, objectURL), "Unable to generate share url.")
|
fatalIf(err.Trace(targetAlias, objectURL), "Unable to generate share url.")
|
||||||
|
|
||||||
return shareURL
|
return shareURL
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -410,7 +411,7 @@ func TestStringReplace(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
gotStr := stringsReplace(testCase.str, testCase.content)
|
gotStr := stringsReplace(context.Background(), testCase.str, testCase.content)
|
||||||
if gotStr != testCase.expectedStr {
|
if gotStr != testCase.expectedStr {
|
||||||
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.expectedStr, gotStr)
|
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.expectedStr, gotStr)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -20,6 +20,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"compress/bzip2"
|
"compress/bzip2"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -45,7 +46,7 @@ var headCmd = cli.Command{
|
|||||||
Name: "head",
|
Name: "head",
|
||||||
Usage: "display first 'n' lines of an object",
|
Usage: "display first 'n' lines of an object",
|
||||||
Action: mainHead,
|
Action: mainHead,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(append(headFlags, ioFlags...), globalFlags...),
|
Flags: append(append(headFlags, ioFlags...), globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -84,7 +85,7 @@ func headURL(sourceURL string, encKeyDB map[string][]prefixSSEPair, nlines int64
|
|||||||
default:
|
default:
|
||||||
var err *probe.Error
|
var err *probe.Error
|
||||||
var metadata map[string]string
|
var metadata map[string]string
|
||||||
if reader, metadata, err = getSourceStreamMetadataFromURL(sourceURL, encKeyDB); err != nil {
|
if reader, metadata, err = getSourceStreamMetadataFromURL(context.Background(), sourceURL, encKeyDB); err != nil {
|
||||||
return err.Trace(sourceURL)
|
return err.Trace(sourceURL)
|
||||||
}
|
}
|
||||||
ctype := metadata["Content-Type"]
|
ctype := metadata["Content-Type"]
|
||||||
|
|||||||
+14
-9
@@ -17,6 +17,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/cmd/ilm"
|
"github.com/minio/mc/cmd/ilm"
|
||||||
json "github.com/minio/mc/pkg/colorjson"
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
@@ -28,7 +30,7 @@ var ilmAddCmd = cli.Command{
|
|||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "add a lifecycle configuration rule to existing (if any) rule(s) on a bucket",
|
Usage: "add a lifecycle configuration rule to existing (if any) rule(s) on a bucket",
|
||||||
Action: mainILMAdd,
|
Action: mainILMAdd,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(ilmAddFlags, globalFlags...),
|
Flags: append(ilmAddFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -51,7 +53,7 @@ EXAMPLES:
|
|||||||
|
|
||||||
2. Add rule for testbucket on s3. Both expiry and transition are number of days.
|
2. Add rule for testbucket on s3. Both expiry and transition are number of days.
|
||||||
{{.Prompt}} {{.HelpName}} --id "Docs" --prefix "doc/" \
|
{{.Prompt}} {{.HelpName}} --id "Docs" --prefix "doc/" \
|
||||||
--expiry-days "200" --transition-days "300 days" \
|
--expiry-days "300" --transition-days "200" \
|
||||||
--storage-class "GLACIER" s3/testbucket
|
--storage-class "GLACIER" s3/testbucket
|
||||||
|
|
||||||
3. Add rule for testbucket on s3. Only expiry is given as number of days and transition is not set.
|
3. Add rule for testbucket on s3. Only expiry is given as number of days and transition is not set.
|
||||||
@@ -129,30 +131,33 @@ func checkILMAddSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calls SetBucketLifecycle with the XML representation of lifecycleConfiguration type.
|
// Calls SetBucketLifecycle with the XML representation of lifecycleConfiguration type.
|
||||||
func mainILMAdd(ctx *cli.Context) error {
|
func mainILMAdd(cliCtx *cli.Context) error {
|
||||||
checkILMAddSyntax(ctx)
|
ctx, cancelILMAdd := context.WithCancel(globalContext)
|
||||||
|
defer cancelILMAdd()
|
||||||
|
|
||||||
|
checkILMAddSyntax(cliCtx)
|
||||||
setILMDisplayColorScheme()
|
setILMDisplayColorScheme()
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
urlStr := args.Get(0)
|
urlStr := args.Get(0)
|
||||||
|
|
||||||
client, err := newClient(urlStr)
|
client, err := newClient(urlStr)
|
||||||
fatalIf(err.Trace(urlStr), "Unable to initialize client for "+urlStr)
|
fatalIf(err.Trace(urlStr), "Unable to initialize client for "+urlStr)
|
||||||
|
|
||||||
// Configuration that is already set.
|
// Configuration that is already set.
|
||||||
lfcCfg, err := client.GetLifecycle()
|
lfcCfg, err := client.GetLifecycle(ctx)
|
||||||
fatalIf(err.Trace(args...), "Unable to fetch lifecycle rules for "+urlStr)
|
fatalIf(err.Trace(args...), "Unable to fetch lifecycle rules for "+urlStr)
|
||||||
|
|
||||||
// Configuration that needs to be set is returned by ilm.GetILMConfigToSet.
|
// Configuration that needs to be set is returned by ilm.GetILMConfigToSet.
|
||||||
// A new rule is added or the rule (if existing) is replaced
|
// A new rule is added or the rule (if existing) is replaced
|
||||||
lfcCfg, err = ilm.ApplyNewILMConfig(ctx, lfcCfg)
|
lfcCfg, err = ilm.ApplyNewILMConfig(cliCtx, lfcCfg)
|
||||||
fatalIf(err.Trace(args...), "Unable to generate new lifecyle rules for the input")
|
fatalIf(err.Trace(args...), "Unable to generate new lifecyle rules for the input")
|
||||||
|
|
||||||
fatalIf(client.SetLifecycle(lfcCfg).Trace(urlStr), "Unable to set new lifecycle rules")
|
fatalIf(client.SetLifecycle(ctx, lfcCfg).Trace(urlStr), "Unable to set new lifecycle rules")
|
||||||
|
|
||||||
printMsg(ilmAddMessage{
|
printMsg(ilmAddMessage{
|
||||||
Status: "success",
|
Status: "success",
|
||||||
Target: urlStr,
|
Target: urlStr,
|
||||||
ID: ctx.String("id"),
|
ID: cliCtx.String("id"),
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+9
-5
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
@@ -29,7 +30,7 @@ var ilmExportCmd = cli.Command{
|
|||||||
Name: "export",
|
Name: "export",
|
||||||
Usage: "export lifecycle configuration in JSON format",
|
Usage: "export lifecycle configuration in JSON format",
|
||||||
Action: mainILMExport,
|
Action: mainILMExport,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -76,17 +77,20 @@ func checkILMExportSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainILMExport(ctx *cli.Context) error {
|
func mainILMExport(cliCtx *cli.Context) error {
|
||||||
checkILMExportSyntax(ctx)
|
ctx, cancelILMExport := context.WithCancel(globalContext)
|
||||||
|
defer cancelILMExport()
|
||||||
|
|
||||||
|
checkILMExportSyntax(cliCtx)
|
||||||
setILMDisplayColorScheme()
|
setILMDisplayColorScheme()
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
urlStr := args.Get(0)
|
urlStr := args.Get(0)
|
||||||
|
|
||||||
client, err := newClient(urlStr)
|
client, err := newClient(urlStr)
|
||||||
fatalIf(err.Trace(args...), "Unable to initialize client for "+urlStr+".")
|
fatalIf(err.Trace(args...), "Unable to initialize client for "+urlStr+".")
|
||||||
|
|
||||||
ilmCfg, err := client.GetLifecycle()
|
ilmCfg, err := client.GetLifecycle(ctx)
|
||||||
fatalIf(err.Trace(args...), "Unable to get lifecycle configuration")
|
fatalIf(err.Trace(args...), "Unable to get lifecycle configuration")
|
||||||
if len(ilmCfg.Rules) == 0 {
|
if len(ilmCfg.Rules) == 0 {
|
||||||
fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr),
|
fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr),
|
||||||
|
|||||||
+9
-5
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
@@ -30,7 +31,7 @@ var ilmImportCmd = cli.Command{
|
|||||||
Name: "import",
|
Name: "import",
|
||||||
Usage: "import lifecycle configuration in JSON format",
|
Usage: "import lifecycle configuration in JSON format",
|
||||||
Action: mainILMImport,
|
Action: mainILMImport,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -84,11 +85,14 @@ func checkILMImportSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainILMImport(ctx *cli.Context) error {
|
func mainILMImport(cliCtx *cli.Context) error {
|
||||||
checkILMImportSyntax(ctx)
|
ctx, cancelILMImport := context.WithCancel(globalContext)
|
||||||
|
defer cancelILMImport()
|
||||||
|
|
||||||
|
checkILMImportSyntax(cliCtx)
|
||||||
setILMDisplayColorScheme()
|
setILMDisplayColorScheme()
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
urlStr := args.Get(0)
|
urlStr := args.Get(0)
|
||||||
|
|
||||||
client, err := newClient(urlStr)
|
client, err := newClient(urlStr)
|
||||||
@@ -97,7 +101,7 @@ func mainILMImport(ctx *cli.Context) error {
|
|||||||
ilmCfg, err := readILMConfig()
|
ilmCfg, err := readILMConfig()
|
||||||
fatalIf(err.Trace(args...), "Unable to read ILM configuration")
|
fatalIf(err.Trace(args...), "Unable to read ILM configuration")
|
||||||
|
|
||||||
fatalIf(client.SetLifecycle(ilmCfg).Trace(urlStr), "Unable to set new lifecycle rules")
|
fatalIf(client.SetLifecycle(ctx, ilmCfg).Trace(urlStr), "Unable to set new lifecycle rules")
|
||||||
|
|
||||||
printMsg(ilmImportMessage{
|
printMsg(ilmImportMessage{
|
||||||
Status: "success",
|
Status: "success",
|
||||||
|
|||||||
+10
-6
@@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -48,7 +49,7 @@ var ilmListCmd = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "pretty print bucket lifecycle configuration",
|
Usage: "pretty print bucket lifecycle configuration",
|
||||||
Action: mainILMList,
|
Action: mainILMList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(ilmListFlags, globalFlags...),
|
Flags: append(ilmListFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -253,17 +254,20 @@ func getILMRowsWithTags(tbl *PrettyTable, cellDataWithTags *[][]string, newRows
|
|||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainILMList(ctx *cli.Context) error {
|
func mainILMList(cliCtx *cli.Context) error {
|
||||||
checkILMListSyntax(ctx)
|
ctx, cancelILMList := context.WithCancel(globalContext)
|
||||||
|
defer cancelILMList()
|
||||||
|
|
||||||
|
checkILMListSyntax(cliCtx)
|
||||||
setILMDisplayColorScheme()
|
setILMDisplayColorScheme()
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
urlStr := args.Get(0)
|
urlStr := args.Get(0)
|
||||||
|
|
||||||
client, err := newClient(urlStr)
|
client, err := newClient(urlStr)
|
||||||
fatalIf(err.Trace(urlStr), "Unable to initialize client for "+urlStr)
|
fatalIf(err.Trace(urlStr), "Unable to initialize client for "+urlStr)
|
||||||
|
|
||||||
ilmCfg, err := client.GetLifecycle()
|
ilmCfg, err := client.GetLifecycle(ctx)
|
||||||
fatalIf(err.Trace(args...), "Unable to get lifecycle")
|
fatalIf(err.Trace(args...), "Unable to get lifecycle")
|
||||||
|
|
||||||
if len(ilmCfg.Rules) == 0 {
|
if len(ilmCfg.Rules) == 0 {
|
||||||
@@ -274,7 +278,7 @@ func mainILMList(ctx *cli.Context) error {
|
|||||||
printMsg(ilmListMessage{
|
printMsg(ilmListMessage{
|
||||||
Status: "success",
|
Status: "success",
|
||||||
Target: urlStr,
|
Target: urlStr,
|
||||||
Context: ctx,
|
Context: cliCtx,
|
||||||
ILMConfig: ilmCfg,
|
ILMConfig: ilmCfg,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ var ilmCmd = cli.Command{
|
|||||||
Name: "ilm",
|
Name: "ilm",
|
||||||
Usage: "configure bucket lifecycle",
|
Usage: "configure bucket lifecycle",
|
||||||
Action: mainILM,
|
Action: mainILM,
|
||||||
Before: setGlobalsFromContext,
|
|
||||||
Flags: globalFlags,
|
Flags: globalFlags,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
|
|||||||
+16
-11
@@ -17,6 +17,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/cmd/ilm"
|
"github.com/minio/mc/cmd/ilm"
|
||||||
json "github.com/minio/mc/pkg/colorjson"
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
@@ -43,7 +45,7 @@ var ilmRemoveCmd = cli.Command{
|
|||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove (if any) existing lifecycle configuration rule with the id",
|
Usage: "remove (if any) existing lifecycle configuration rule with the id",
|
||||||
Action: mainILMRemove,
|
Action: mainILMRemove,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(ilmRemoveFlags, globalFlags...),
|
Flags: append(ilmRemoveFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -112,33 +114,36 @@ func checkILMRemoveSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainILMRemove(ctx *cli.Context) error {
|
func mainILMRemove(cliCtx *cli.Context) error {
|
||||||
checkILMRemoveSyntax(ctx)
|
ctx, cancelILMImport := context.WithCancel(globalContext)
|
||||||
|
defer cancelILMImport()
|
||||||
|
|
||||||
|
checkILMRemoveSyntax(cliCtx)
|
||||||
setILMDisplayColorScheme()
|
setILMDisplayColorScheme()
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
urlStr := args.Get(0)
|
urlStr := args.Get(0)
|
||||||
|
|
||||||
client, err := newClient(urlStr)
|
client, err := newClient(urlStr)
|
||||||
fatalIf(err.Trace(args...), "Unable to initialize client for "+urlStr+".")
|
fatalIf(err.Trace(args...), "Unable to initialize client for "+urlStr+".")
|
||||||
|
|
||||||
ilmCfg, err := client.GetLifecycle()
|
ilmCfg, err := client.GetLifecycle(ctx)
|
||||||
fatalIf(err.Trace(urlStr), "Unable to fetch lifecycle rules")
|
fatalIf(err.Trace(urlStr), "Unable to fetch lifecycle rules")
|
||||||
|
|
||||||
ilmAll := ctx.Bool("all")
|
ilmAll := cliCtx.Bool("all")
|
||||||
ilmForce := ctx.Bool("force")
|
ilmForce := cliCtx.Bool("force")
|
||||||
|
|
||||||
if ilmAll && ilmForce {
|
if ilmAll && ilmForce {
|
||||||
ilmCfg.Rules = nil // Remove all rules
|
ilmCfg.Rules = nil // Remove all rules
|
||||||
} else {
|
} else {
|
||||||
ilmCfg, err = ilm.RemoveILMRule(ilmCfg, ctx.String("id"))
|
ilmCfg, err = ilm.RemoveILMRule(ilmCfg, cliCtx.String("id"))
|
||||||
fatalIf(err.Trace(urlStr, ctx.String("id")), "Unable to remove rule by id")
|
fatalIf(err.Trace(urlStr, cliCtx.String("id")), "Unable to remove rule by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
fatalIf(client.SetLifecycle(ilmCfg).Trace(urlStr), "Unable to set lifecycle rules")
|
fatalIf(client.SetLifecycle(ctx, ilmCfg).Trace(urlStr), "Unable to set lifecycle rules")
|
||||||
|
|
||||||
printMsg(ilmRmMessage{
|
printMsg(ilmRmMessage{
|
||||||
Status: "success",
|
Status: "success",
|
||||||
ID: ctx.String("id"),
|
ID: cliCtx.String("id"),
|
||||||
All: ilmAll,
|
All: ilmAll,
|
||||||
Target: urlStr,
|
Target: urlStr,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// rule ID field column width in table output
|
// rule ID field column width in table output
|
||||||
idColumnWidth int = 12
|
idColumnWidth int = 16
|
||||||
// rule prefix field column width in table output
|
// rule prefix field column width in table output
|
||||||
prefixColumnWidth int = 10
|
prefixColumnWidth int = 16
|
||||||
// StatusColumnWidth column width in table output
|
// StatusColumnWidth column width in table output
|
||||||
statusColumnWidth int = 12
|
statusColumnWidth int = 12
|
||||||
// ExpiryColumnWidth column width in table output
|
// ExpiryColumnWidth column width in table output
|
||||||
@@ -302,7 +302,10 @@ func checkAddTableCell(rowArr *[]string, rowCheck map[string]int, cellInfo table
|
|||||||
if colIdx, ok := rowCheck[cellInfo.labelKey]; ok {
|
if colIdx, ok := rowCheck[cellInfo.labelKey]; ok {
|
||||||
if len(cellInfo.label)%2 != 0 && len(cellInfo.label) < cellInfo.columnWidth {
|
if len(cellInfo.label)%2 != 0 && len(cellInfo.label) < cellInfo.columnWidth {
|
||||||
cellInfo.label += " "
|
cellInfo.label += " "
|
||||||
|
} else if len(cellInfo.label) > (cellInfo.columnWidth - 2) { // 2 dots to indicate text longer than column width
|
||||||
|
cellInfo.label = cellInfo.label[:(cellInfo.columnWidth-6)] + ".."
|
||||||
}
|
}
|
||||||
|
|
||||||
(*rowArr)[colIdx] = getAlignedText(cellInfo.label, cellInfo.align, cellInfo.columnWidth)
|
(*rowArr)[colIdx] = getAlignedText(cellInfo.label, cellInfo.align, cellInfo.columnWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -40,7 +41,7 @@ var legalHoldCmd = cli.Command{
|
|||||||
Name: "legalhold",
|
Name: "legalhold",
|
||||||
Usage: "set legal hold for object(s)",
|
Usage: "set legal hold for object(s)",
|
||||||
Action: mainLegalHold,
|
Action: mainLegalHold,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(lhFlags, globalFlags...),
|
Flags: append(lhFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -86,12 +87,15 @@ func (l legalHoldCmdMessage) JSON() string {
|
|||||||
|
|
||||||
// setRetention - Set Retention for all objects within a given prefix.
|
// setRetention - Set Retention for all objects within a given prefix.
|
||||||
func setLegalHold(urlStr string, lhold minio.LegalHoldStatus, isRecursive bool) error {
|
func setLegalHold(urlStr string, lhold minio.LegalHoldStatus, isRecursive bool) error {
|
||||||
|
ctx, cancelLegalHold := context.WithCancel(globalContext)
|
||||||
|
defer cancelLegalHold()
|
||||||
|
|
||||||
clnt, err := newClient(urlStr)
|
clnt, err := newClient(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
||||||
}
|
}
|
||||||
if !isRecursive {
|
if !isRecursive {
|
||||||
err = clnt.PutObjectLegalHold(lhold)
|
err = clnt.PutObjectLegalHold(ctx, lhold)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorIf(err.Trace(urlStr), "Failed to set legal hold on `"+urlStr+"` successfully")
|
errorIf(err.Trace(urlStr), "Failed to set legal hold on `"+urlStr+"` successfully")
|
||||||
} else {
|
} else {
|
||||||
@@ -107,7 +111,7 @@ func setLegalHold(urlStr string, lhold minio.LegalHoldStatus, isRecursive bool)
|
|||||||
alias, _, _ := mustExpandAlias(urlStr)
|
alias, _, _ := mustExpandAlias(urlStr)
|
||||||
var cErr error
|
var cErr error
|
||||||
errorsFound := false
|
errorsFound := false
|
||||||
for content := range clnt.List(isRecursive, false, false, DirNone) {
|
for content := range clnt.List(ctx, isRecursive, false, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Unable to list folder.")
|
errorIf(content.Err.Trace(clnt.GetURL().String()), "Unable to list folder.")
|
||||||
cErr = exitStatus(globalErrorExitStatus) // Set the exit status.
|
cErr = exitStatus(globalErrorExitStatus) // Set the exit status.
|
||||||
@@ -119,7 +123,7 @@ func setLegalHold(urlStr string, lhold minio.LegalHoldStatus, isRecursive bool)
|
|||||||
errorIf(content.Err.Trace(clnt.GetURL().String()), "Invalid URL")
|
errorIf(content.Err.Trace(clnt.GetURL().String()), "Invalid URL")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
probeErr := newClnt.PutObjectLegalHold(lhold)
|
probeErr := newClnt.PutObjectLegalHold(ctx, lhold)
|
||||||
if probeErr != nil {
|
if probeErr != nil {
|
||||||
errorsFound = true
|
errorsFound = true
|
||||||
errorIf(probeErr.Trace(content.URL.Path), "Failed to set legal hold on `"+content.URL.Path+"` successfully")
|
errorIf(probeErr.Trace(content.URL.Path), "Failed to set legal hold on `"+content.URL.Path+"` successfully")
|
||||||
|
|||||||
+7
-3
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -42,7 +43,7 @@ var lockCmd = cli.Command{
|
|||||||
Name: "lock",
|
Name: "lock",
|
||||||
Usage: "set and get object lock configuration",
|
Usage: "set and get object lock configuration",
|
||||||
Action: mainLock,
|
Action: mainLock,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(lockFlags, globalFlags...),
|
Flags: append(lockFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -99,11 +100,14 @@ func lock(urlStr string, mode minio.RetentionMode, validity uint64, unit minio.V
|
|||||||
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
fatalIf(err.Trace(), "Cannot parse the provided url.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx, cancelLock := context.WithCancel(globalContext)
|
||||||
|
defer cancelLock()
|
||||||
|
|
||||||
if clearLock || mode != "" {
|
if clearLock || mode != "" {
|
||||||
err = client.SetObjectLockConfig(mode, validity, unit)
|
err = client.SetObjectLockConfig(ctx, mode, validity, unit)
|
||||||
fatalIf(err, "Cannot enable object lock configuration on the specified bucket.")
|
fatalIf(err, "Cannot enable object lock configuration on the specified bucket.")
|
||||||
} else {
|
} else {
|
||||||
mode, validity, unit, err = client.GetObjectLockConfig()
|
mode, validity, unit, err = client.GetObjectLockConfig(ctx)
|
||||||
fatalIf(err, "Cannot get object lock configuration on the specified bucket.")
|
fatalIf(err, "Cannot get object lock configuration on the specified bucket.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-17
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@@ -43,7 +44,7 @@ var lsCmd = cli.Command{
|
|||||||
Name: "ls",
|
Name: "ls",
|
||||||
Usage: "list buckets and objects",
|
Usage: "list buckets and objects",
|
||||||
Action: mainList,
|
Action: mainList,
|
||||||
Before: setGlobalsFromContext,
|
Before: initBeforeRunningCmd,
|
||||||
Flags: append(lsFlags, globalFlags...),
|
Flags: append(lsFlags, globalFlags...),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
{{.HelpName}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
@@ -76,9 +77,9 @@ EXAMPLES:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkListSyntax - validate all the passed arguments
|
// checkListSyntax - validate all the passed arguments
|
||||||
func checkListSyntax(ctx *cli.Context) {
|
func checkListSyntax(ctx context.Context, cliCtx *cli.Context) {
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
if !ctx.Args().Present() {
|
if !cliCtx.Args().Present() {
|
||||||
args = []string{"."}
|
args = []string{"."}
|
||||||
}
|
}
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
@@ -87,11 +88,11 @@ func checkListSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// extract URLs.
|
// extract URLs.
|
||||||
URLs := ctx.Args()
|
URLs := cliCtx.Args()
|
||||||
isIncomplete := ctx.Bool("incomplete")
|
isIncomplete := cliCtx.Bool("incomplete")
|
||||||
|
|
||||||
for _, url := range URLs {
|
for _, url := range URLs {
|
||||||
_, _, err := url2Stat(url, false, nil)
|
_, _, err := url2Stat(ctx, url, false, nil)
|
||||||
if err != nil && !isURLPrefixExists(url, isIncomplete) {
|
if err != nil && !isURLPrefixExists(url, isIncomplete) {
|
||||||
// Bucket name empty is a valid error for 'ls myminio',
|
// Bucket name empty is a valid error for 'ls myminio',
|
||||||
// treat it as such.
|
// treat it as such.
|
||||||
@@ -106,23 +107,26 @@ func checkListSyntax(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mainList - is a handler for mc ls command
|
// mainList - is a handler for mc ls command
|
||||||
func mainList(ctx *cli.Context) error {
|
func mainList(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelList := context.WithCancel(globalContext)
|
||||||
|
defer cancelList()
|
||||||
|
|
||||||
// Additional command specific theme customization.
|
// Additional command specific theme customization.
|
||||||
console.SetColor("File", color.New(color.Bold))
|
console.SetColor("File", color.New(color.Bold))
|
||||||
console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
|
console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
|
||||||
console.SetColor("Size", color.New(color.FgYellow))
|
console.SetColor("Size", color.New(color.FgYellow))
|
||||||
console.SetColor("Time", color.New(color.FgGreen))
|
console.SetColor("Time", color.New(color.FgGreen))
|
||||||
|
|
||||||
// check 'ls' cli arguments.
|
// check 'ls' cliCtx arguments.
|
||||||
checkListSyntax(ctx)
|
checkListSyntax(ctx, cliCtx)
|
||||||
|
|
||||||
// Set command flags from context.
|
// Set command flags from context.
|
||||||
isRecursive := ctx.Bool("recursive")
|
isRecursive := cliCtx.Bool("recursive")
|
||||||
isIncomplete := ctx.Bool("incomplete")
|
isIncomplete := cliCtx.Bool("incomplete")
|
||||||
|
|
||||||
args := ctx.Args()
|
args := cliCtx.Args()
|
||||||
// mimic operating system tool behavior.
|
// mimic operating system tool behavior.
|
||||||
if !ctx.Args().Present() {
|
if !cliCtx.Args().Present() {
|
||||||
args = []string{"."}
|
args = []string{"."}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +134,9 @@ func mainList(ctx *cli.Context) error {
|
|||||||
for _, targetURL := range args {
|
for _, targetURL := range args {
|
||||||
clnt, err := newClient(targetURL)
|
clnt, err := newClient(targetURL)
|
||||||
fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.")
|
fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.")
|
||||||
|
|
||||||
if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) {
|
if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) {
|
||||||
var st *ClientContent
|
var st *ClientContent
|
||||||
st, err = clnt.Stat(isIncomplete, false, nil)
|
st, err = clnt.Stat(ctx, isIncomplete, false, nil)
|
||||||
if st != nil && err == nil && st.Type.IsDir() {
|
if st != nil && err == nil && st.Type.IsDir() {
|
||||||
targetURL = targetURL + string(clnt.GetURL().Separator)
|
targetURL = targetURL + string(clnt.GetURL().Separator)
|
||||||
clnt, err = newClient(targetURL)
|
clnt, err = newClient(targetURL)
|
||||||
@@ -141,7 +144,7 @@ func mainList(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e := doList(clnt, isRecursive, isIncomplete); e != nil {
|
if e := doList(ctx, clnt, isRecursive, isIncomplete); e != nil {
|
||||||
cErr = e
|
cErr = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -106,14 +107,15 @@ func getKey(c *ClientContent) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doList - list all entities inside a folder.
|
// doList - list all entities inside a folder.
|
||||||
func doList(clnt Client, isRecursive, isIncomplete bool) error {
|
func doList(ctx context.Context, clnt Client, isRecursive, isIncomplete bool) error {
|
||||||
prefixPath := clnt.GetURL().Path
|
prefixPath := clnt.GetURL().Path
|
||||||
separator := string(clnt.GetURL().Separator)
|
separator := string(clnt.GetURL().Separator)
|
||||||
if !strings.HasSuffix(prefixPath, separator) {
|
if !strings.HasSuffix(prefixPath, separator) {
|
||||||
prefixPath = prefixPath[:strings.LastIndex(prefixPath, separator)+1]
|
prefixPath = prefixPath[:strings.LastIndex(prefixPath, separator)+1]
|
||||||
}
|
}
|
||||||
|
|
||||||
var cErr error
|
var cErr error
|
||||||
for content := range clnt.List(isRecursive, isIncomplete, false, DirNone) {
|
for content := range clnt.List(ctx, isRecursive, isIncomplete, false, DirNone) {
|
||||||
if content.Err != nil {
|
if content.Err != nil {
|
||||||
switch content.Err.ToGoError().(type) {
|
switch content.Err.ToGoError().(type) {
|
||||||
// handle this specifically for filesystem related errors.
|
// handle this specifically for filesystem related errors.
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user