hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/gils/cp.rv
blob: 5006acb103626f771a8aaed5d15b6d105ab6b41d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# copy a file not cyberpunk
# HAAAAAANNNNKKKK

const context = env.ctx
if context.argv:len() < 3 do puts("usage: cp <source> <destination>\n") end
else do
  const source = expand_path(context.argv[1])
  const destination = expand_path(context.argv[2])
  const size = fs:size(source)
  if size < 0 do puts("cp: #{source}: no such file\n") end
  else do
    const contents = if size > 0 fs:read_bytes(source, 0, size) else ""
    if fs:store(destination, contents) == 1 do puts("#{source} -> #{destination}\n") end
  end
end