Hacker News new | past | comments | ask | show | jobs | submit login

I am not sure what TTCTTOU is, but what you are saying needs transaction like semantics in filesystems. So its more of a property of an FS instead of a language.

All the common FS (in linux .. ext* xfs) do not have that these.




“time to check to time to use”

As you intuited, a problem that arises in environments that lack transactions/locks/etc


> All the common FS (in linux .. ext* xfs) do not have that these

You know that files are nameless on Unix, right?


> do not have that these

I was referring to the transaction semantics


> 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




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: