-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a check for it and now we will see error: 'is a directory' #1
base: master
Are you sure you want to change the base?
Conversation
Added the suggested error message |
@dumblob Any updates? :) |
@kunal thanks for asking - I'm actually quitting my job, moving to a different place and changing even a country (state). I was expecting I'll manage better, but it seems I'll be busy until the end of January. Starting from February I'm though quite free on the other hand, so I'll devote significantly more time to community work than during the last 2 years. I've started testing this patch and found out we're having the same issue as Python 3 had (or maybe still has under certain circumstances due to its modularity) - namely calling |
@dumblob I will check and get back to you. |
Not sure how to resolve this :) Checked the Python implementation as well. Check line 455: https://github.com/python/cpython/blob/bcda8f1d42a98d9022736dd52d855be8e220fe15/Modules/_io/fileio.c There is a check for a directory. |
I gave it a thought and I'm pretty confident we shall: a) open the file without checking anything (like the current upstream) This has basically all advantages (no atomicity issue like when calling I did some measurements for the very worst case on my 10 years old machine with HDD (no SSD nor anything faster) on Linux 4.19.34-1-lts with
So, basically we'll do something like: static FILE* DaoIO_OpenFile( DaoProcess *proc, DString *name, const char *mode, int silent )
{
...
fin = Dao_OpenFile( fname->chars, mode );
Dstring_Delete( fname );
#ifndef WIN32
struct stat s;
fstat( fileno( fin ), &s );
#endif
if( fin == NULL && silent == 0 &&
#ifndef WIN32
S_ISDIR( s.st_mode ) != 0
#endif
){
... So, now we also know, that |
Thanks for the details :) I will try this out. Only downside I feel here is we wont be able to specifically let the user know that it was a directory that he/she was trying to open and hence the error. Also not sure why should we let open the file at first place. Why dont we just fstat first and then once we are sure its not a directory we let file to be opened because anyway we are doing this check later once we open the file. This also allows us to raise a specific error saying opening directories is not allowed. Let me know what do you think. |
Well, there is actually a check for whether it's a directory or not (see
Dao is a language with first class support for concurrent parallelism. Thus we must not allow any race conditions. File systems on UNIXes (including Linux) are not transactional and thus it's impossible to run
I don't see any issue with raising a specific error - see the code snippet from my last comment. |
Btw. I've run another benchmark to see if we could first just open the path as read only (disregarding which opening mode the user has chosen) and if it's a file (not a directory), then just #include <stdio.h> // fopen, fclose, printf, FILE
int main( int a, char *aa[] ){
a = a; aa = aa;
FILE *f = NULL;
for( int i=0; i<10000000; ++i ){
f = fopen( "file.txt", "r" );
if( f == NULL ){ printf( "ERR fopen() failed\n" ); return 1; }
fclose( f );
}
return 0;
} ( #include <stdio.h> // fopen, fclose, printf, FILE
int main( int a, char *aa[] ){
a = a; aa = aa;
FILE *f = NULL;
for( int i=0; i<10000000; ++i ){
f = fopen( "file.txt", "w+" );
if( f == NULL ){ printf( "ERR fopen() failed\n" ); return 1; }
fclose( f );
}
return 0;
} ( #include <stdio.h> // fopen, fclose, printf, FILE
int main( int a, char *aa[] ){
a = a; aa = aa;
FILE *f = NULL;
for( int i=0; i<10000000; ++i ){
f = fopen( "file.txt", "r" );
if( f == NULL ){ printf( "ERR fopen() failed\n" ); return 1; }
f = freopen( NULL, "w+", f );
if( f == NULL ){ printf( "ERR freopen() failed\n" ); return 1; }
fclose( f );
}
return 0;
} ( ResultsThe file already existed, had about 5 bytes inside and wasn't a sparse file. The filesystem was ext4 under Linux LTS 5.4.32.
|
Added a check for it and now we will see error: 'is a directory'. Resolves daokoder#523 in main repo https://github.com/daokoder/dao