Skip to content

Commit 3883924

Browse files
committed
fixup
1 parent f80f52c commit 3883924

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

src/AzStorage.jl

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,31 @@ function generate_user_delegation_sas(c::AzContainer, b::AbstractString; permiss
976976
"sig=$signed_string"
977977
end
978978

979-
function Base.cp(inc::AzContainer, inb::AbstractString, outc::AzContainer, outb::AbstractString; showprogress=false)
979+
function status(c::AzContainer, b::AbstractString)
980+
local copy_progress
981+
r_status = @retry c.nretry HTTP.request(
982+
"GET",
983+
"https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/$(addprefix(c,b))",
984+
[
985+
"Authorization" => "Bearer $(token(c.session))",
986+
"x-ms-version" => API_VERSION
987+
];
988+
retry = false,
989+
verbose = c.verbose,
990+
connect_timeout = c.connect_timeout,
991+
readtimeout = c.read_timeout
992+
)
993+
994+
copy_status = HTTP.header(r_status, "x-ms-copy-status")
995+
copy_progress = HTTP.header(r_status, "x-ms-copy-progress")
996+
copy_reason = HTTP.header(r_status, "x-ms-copy-status-description")
997+
998+
Dict("status"=>copy_status, "progress"=>copy_progress, "reason"=>copy_reason)
999+
1000+
nothing
1001+
end
1002+
1003+
function Base.cp(inc::AzContainer, inb::AbstractString, outc::AzContainer, outb::AbstractString; showprogress=false, async=false)
9801004
source_url = "https://$(inc.storageaccount).blob.core.windows.net/$(inc.containername)/$(addprefix(inc,inb))"
9811005

9821006
if inc.storageaccount != outc.storageaccount
@@ -990,7 +1014,7 @@ function Base.cp(inc::AzContainer, inb::AbstractString, outc::AzContainer, outb:
9901014
"x-ms-copy-source" => source_url
9911015
]
9921016

993-
r = @retry inc.nretry HTTP.request(
1017+
r_copy = @retry inc.nretry HTTP.request(
9941018
"PUT",
9951019
"https://$(outc.storageaccount).blob.core.windows.net/$(outc.containername)/$(addprefix(outc,outb))",
9961020
headers;
@@ -1000,37 +1024,26 @@ function Base.cp(inc::AzContainer, inb::AbstractString, outc::AzContainer, outb:
10001024
readtimeout = inc.read_timeout
10011025
)
10021026

1003-
if r.status == 202
1004-
local copy_progress
1027+
if !async && r_copy.status == 202
10051028
while true
1006-
r_status = HTTP.request(
1007-
"GET",
1008-
"https://$(outc.storageaccount).blob.core.windows.net/$(outc.containername)/$(addprefix(outc,outb))",
1009-
[
1010-
"Authorization" => "Bearer $(token(outc.session))",
1011-
"x-ms-version" => API_VERSION
1012-
];
1013-
retry = false,
1014-
verbose = inc.verbose,
1015-
connect_timeout = inc.connect_timeout,
1016-
readtimeout = inc.read_timeout
1017-
)
1018-
1019-
copy_status = HTTP.header(r_status, "x-ms-copy-status")
1020-
copy_progress = HTTP.header(r_status, "x-ms-copy-progress")
1021-
if copy_status == "success"
1022-
break
1029+
local stat
1030+
try
1031+
stat = cp_status(outc, outb)
1032+
catch
1033+
@warn "unable to get copy status for blob copy, retrying..."
1034+
stat = Dict("status"=>"unknown")
10231035
end
1024-
if copy_status == "aborted"
1025-
reason = HTTP.header(r_status, "x-ms-copy-status-description")
1026-
error("blob copy aborted, src=$(inc.storageaccount): $(inc.containername)/$(addprefix(inc,inb)), dest=$(outc.storageaccount): $(outc.containername)/$(addprefix(outc,outb)), reason=$reason")
1036+
1037+
if stat["status"] == "success"
1038+
break
1039+
elseif stat["status"] == "aborted"
1040+
error("blob copy aborted, dest=$(outc.storageaccount): $(outc.containername)/$(addprefix(outc,outb)), reason=$(stat["reason"])")
10271041
break
1042+
elseif stat["status"] == "pending" && showprogress
1043+
print("copy progress: $(stat["progress"])\r")
10281044
end
1029-
1030-
showprogress && print("copy progress: $copy_progress bytes\r")
1031-
sleep(.1)
1045+
sleep(1)
10321046
end
1033-
showprogress && print("copy progress: $copy_progress bytes\r\n")
10341047
end
10351048

10361049
nothing
@@ -1406,6 +1419,6 @@ Note that the information stored is global, and not specfic to any one given IO
14061419
"""
14071420
getperf_counters() = @ccall libAzStorage.getperf_counters()::PerfCounters
14081421

1409-
export AzContainer, containers, readdlm, writedlm
1422+
export AzContainer, containers, readdlm, status, writedlm
14101423

14111424
end

0 commit comments

Comments
 (0)