handlers/copy.lua

Wed, 15 Dec 2021 10:37:47 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 15 Dec 2021 10:37:47 +0200
changeset 41
8040d3a298e4
parent 35
2f927eae429b
permissions
-rwxr-xr-x

Add ANTI-ABUSE LICENSE

2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
2 --@module handlers.copy
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
3
26
77cd7b8fb6a6 Rename path.lua mypath.lua not conflict with other lua path modules.
Tuomo Valkonen <tuomov@iki.fi>
parents: 7
diff changeset
4 local path=require("mypath")
35
2f927eae429b Don't auto-create directories that will be empty
Tuomo Valkonen <tuomov@iki.fi>
parents: 26
diff changeset
5 local lfs=require("lfs")
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
7 local handlers_copy={}
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
8
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
9 local dependency=require("dependency")
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
10 local log=require("log")
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
11
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
12 function handlers_copy.phase1(file, env)
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
15 function handlers_copy.phase2(file, env)
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
16 local src=path.join(env.paths.src, file)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
17 local dst=path.join(env.paths.dst, file)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
18 if dependency.simple_update_check(dst, {src}) then
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
19 log.log("Copy "..file.."\n")
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
20 local f = io.openX(src, 'r')
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
21 local dstf = io.openX(dst, 'w')
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
22 while true do
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
23 local data=f:read(1024*1024)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
24 if not data then
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
25 break
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
26 end
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
27 dstf:write(data)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
28 end
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
29 end
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 end
7
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
31
038275cd92ed Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
32 return handlers_copy

mercurial