hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/gils/mv.rv
blob: d87cb28e50850becd309d9afc1bea2ffbd21ab87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# move or rename a file

const context = env.ctx
if context.argv:len() < 3 do
  fail("usage: mv <source> <destination>\n")
end else do
  const source = expand_path(context.argv[1])
  const destination = expand_path(context.argv[2])
  const size = vfs:size(source)

  if size < 0 do
    fail("mv: #{source}: no such file\n")
  end else do
    const contents = if (size > 0) vfs:read_bytes(source, 0, size) else ""
    if vfs:store(destination, contents) == 1 do
      vfs:unlink(source)
      puts("#{source} -> #{destination}\n")
    end
  end
end