News for hackers. Stuff that matters.
Re:C++ still isn't cutting it by sudeepj on Sunday October 18, 2020 @10:14PM (#24822812)
> do not have that these

I was referring to the transaction semantics

Re:C++ still isn't cutting it by Iwan-Zotow on Wednesday October 21, 2020 @05:25PM (#24852363)
> 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