1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local function _prepare_source(dir)
os.mkdir(dir)
io.writefile(path.join(dir, "foo.txt"), "foo")
io.writefile(path.join(dir, "bar.txt"), "bar")
end
function main()
local root = os.tmpfile() .. ".os_async_copy"
local srcdir = path.join(root, "src")
local dstdir = path.join(root, "dst")
_prepare_source(srcdir)
print("source prepared: %s", srcdir)
local files = os.files(path.join(srcdir, "*.txt"), {async = true})
assert(files and #files == 2)
print("async enumerate: %d files", #files)
os.cp(srcdir, dstdir, {async = true})
assert(os.isdir(dstdir))
print("async copy done: %s", dstdir)
files = os.files(path.join(dstdir, "*.txt"), {async = true})
assert(files and #files == 2)
os.rm(dstdir, {async = true})
assert(not os.isdir(dstdir))
print("dst removed async")
os.rm(srcdir, {async = true})
os.tryrm(root)
print("async copy test finished")
end
|