Skip to content

Commit 616f29e

Browse files
committed
fixup
1 parent 5862cd6 commit 616f29e

File tree

2 files changed

+57
-59
lines changed

2 files changed

+57
-59
lines changed

src/AzStorage.jl

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,43 @@ Serialize and write data to `io::AzObject`. See serialize(conainer, blobname, d
534534
Serialization.serialize(o::AzObject, data) = serialize(o.container, o.name, data)
535535

536536
"""
537-
touch(container, "blobname")
537+
touch(c, b)
538538
539-
Create a zero-byte object with name `blobname` in `container::AzContainer`.
539+
Update the metadata of a blob `b::AbstractString` in container `c::AzContainer`, changing
540+
the datset's 'LAST MODIFIED' date. If the blob does not exist, then a zero-byte blob is
541+
created.
540542
541543
# Example
542544
```
543545
container = AzContainer("mycontainer";storageaccount="mystorageaccount")
544546
touch(container, "foo")
545547
```
546548
"""
547-
Base.touch(c::AzContainer, o::AbstractString) = write(c, o, "\0")
549+
function Base.touch(c::AzContainer, o::AbstractString)
550+
if !isfile(c, o)
551+
write(c, o, "\0")
552+
else
553+
@retry c.nretry HTTP.request(
554+
"PUT",
555+
"https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/$(addprefix(c,o))?comp=metadata",
556+
[
557+
"Authorization" => "Bearer $(token(c.session))",
558+
"x-ms-version" => API_VERSION,
559+
"x-ms-meta-touched" => string(Dates.now(UTC))
560+
];
561+
retry = false,
562+
verbose = c.verbose,
563+
connect_timeout = c.connect_timeout,
564+
readtimeout = c.read_timeout)
565+
end
566+
end
567+
568+
"""
569+
touch(o)
570+
571+
Update the metadata of a blob `o::AzObject`, changing the dataset's 'LAST MODIFIED' date.
572+
"""
573+
Base.touch(o::AzObject) = touch(o.container, o.name)
548574

549575
"""
550576
touch(io::AzObject)
@@ -1416,34 +1442,6 @@ Note that the information stored is global, and not specfic to any one given IO
14161442
"""
14171443
getperf_counters() = @ccall libAzStorage.getperf_counters()::PerfCounters
14181444

1419-
"""
1420-
touch!(c, b)
1421-
1422-
Update the metadata of a blob `b::AbstractString` in container `c::AzContainer`, changing
1423-
the datset's 'LAST MODIFIED' date.
1424-
"""
1425-
function Base.touch(c::AzContainer, o::AbstractString)
1426-
@retry c.nretry HTTP.request(
1427-
"PUT",
1428-
"https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/$(addprefix(c,o))?comp=metadata",
1429-
[
1430-
"Authorization" => "Bearer $(token(c.session))",
1431-
"x-ms-version" => API_VERSION,
1432-
"x-ms-meta-touched" => string(Dates.now(UTC))
1433-
];
1434-
retry = false,
1435-
verbose = c.verbose,
1436-
connect_timeout = c.connect_timeout,
1437-
readtimeout = c.read_timeout)
1438-
end
1439-
1440-
"""
1441-
touch(o)
1442-
1443-
Update the metadata of a blob `o::AzObject`, changing the dataset's 'LAST MODIFIED' date.
1444-
"""
1445-
Base.touch(o::AzObject) = touch(o.container, o.name)
1446-
14471445
"""
14481446
tier!(c, b[; tier="Hot"])
14491447

test/runtests.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,34 @@ end
302302
rm(c)
303303
end
304304

305+
@testset "Containers and Objects, touch" begin
306+
r = uuid4()
307+
c = AzContainer("foo-$r"; storageaccount, session)
308+
mkpath(c)
309+
write(c, "test.txt", "Hello")
310+
311+
r1 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
312+
t1 = HTTP.header(r1, "Last-Modified")
313+
314+
sleep(5)
315+
316+
touch(c, "test.txt")
317+
r2 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
318+
t2 = HTTP.header(r2, "Last-Modified")
319+
320+
@test t1 != t2
321+
322+
sleep(5)
323+
324+
touch(joinpath(c, "test.txt"))
325+
r3 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
326+
t3 = HTTP.header(r3, "Last-Modified")
327+
328+
@test t3 != t2
329+
330+
rm(c)
331+
end
332+
305333
@testset "isdir, edge case" begin
306334
c = AzContainer(""; storageaccount="", session=session)
307335
@test isdir(c) == false
@@ -727,34 +755,6 @@ end
727755
rm(c)
728756
end
729757

730-
@testset "touch" begin
731-
r = uuid4()
732-
c = AzContainer("foo-$r"; storageaccount, session)
733-
mkpath(c)
734-
write(c, "test.txt", "Hello")
735-
736-
r1 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
737-
t1 = HTTP.header(r1, "Last-Modified")
738-
739-
sleep(5)
740-
741-
touch(c, "test.txt")
742-
r2 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
743-
t2 = HTTP.header(r2, "Last-Modified")
744-
745-
@test t1 != t2
746-
747-
sleep(5)
748-
749-
touch(joinpath(c, "test.txt"))
750-
r3 = HTTP.request("HEAD", "https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/test.txt", ["Authorization" => "Bearer $(token(c.session))", "x-ms-version" => AzStorage.API_VERSION])
751-
t3 = HTTP.header(r3, "Last-Modified")
752-
753-
@test t3 != t2
754-
755-
rm(c)
756-
end
757-
758758
# TODO: CI is showing a seg-fault on Apple, but I do not have an Apple machine to help debug.
759759
if !Sys.iswindows() && !Sys.isapple()
760760
@testset "C token refresh, write" begin

0 commit comments

Comments
 (0)