1

Uploades file represented as tmpfile() and will be removed then script exits. How to hardlink this file to keep its content after removing tmpfile?

How to get name of file by its handle?

> a=io.tmpfile()
> print(a)
file (0x20c8790)
> lfs=require"lfs"
> lfs.link(a,"/tmp/aaaa")
stdin:1: bad argument #1 to 'link' (string expected, got FILE*)
stack traceback:
    [C]: in function 'lfs.link'
    stdin:1: in main chunk
    [C]: in ?

This file is too big to copy it by byte to another.

eri
  • 3,133
  • 1
  • 23
  • 35
  • Just use regular files. On windows I know there exists way to get name by handle. Also it possible get handle from FILE* (but there may some problem if you link with static MSCRT). But do you really need this instead of just create file by hand and use it as tmp? This is my impl. https://github.com/moteus/lua-path/blob/master/lua/path.lua#L229 – moteus Feb 28 '16 at 11:00
  • 1
    Use [os.tmpname()](http://www.lua.org/manual/5.3/manual.html#pdf-os.tmpname) instead of io.tmpfile() – Egor Skriptunoff Feb 28 '16 at 12:04
  • io.tmpfile() is inside library, so i wanted not to edit this – eri Feb 29 '16 at 10:53

1 Answers1

1

io.tmpfile uses tmpfile of stdio.h, so it wont be possible to adjust this exported function. you can use libraries such as pl.path to get full path of temp file.

Kosho-b
  • 161
  • 5