Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> let f = File::open("username.txt");

> /what if the file is deleted here?/

you don't need transaction semantics here.

On Unix file is basically inode with counter. If it doesn't have record (aka name) in directory but non-zero counter, it would exist.

So on open(2) counter is bumped up and is equal to 2 (or higher if there are hardlinks), one for the directory record and one for program running it.

If you remove record from directory (aka `rm filename`), counter would decrease by 1, but it is still non-zero, program still has it open, could read its content, etc. Only after close(2) counter would decrease to 0 and file would be gone.

Just tested it on Ubuntu 20.4 with simple C program



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: