Skip to content

Is. #681 - read-only files, and dirs #926

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

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/tidylib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,19 +1125,26 @@ int TIDY_CALL tidyParseSource( TidyDoc tdoc, TidyInputSource* source )
return tidyDocParseSource( doc, source );
}


#ifdef WIN32
#define M_IS_DIR _S_IFDIR
#else // !WIN32
#define M_IS_DIR S_IFDIR
#endif
int tidyDocParseFile( TidyDocImpl* doc, ctmbstr filnam )
{
int status = -ENOENT;
FILE* fin = fopen( filnam, "r+" );

if ( !fin )
FILE* fin = 0;
struct stat sbuf = { 0 }; /* Is. #681 - read-only files */
if ( stat(filnam,&sbuf) != 0 )
{
TY_(ReportFileError)( doc, filnam, FILE_NOT_FILE );
return status;
}

fclose( fin );
if (sbuf.st_mode & M_IS_DIR) /* and /NOT/ if a DIRECTORY */
{
TY_(ReportFileError)(doc, filnam, FILE_NOT_FILE);
return status;
}

#ifdef _WIN32
return TY_(DocParseFileWithMappedFile)( doc, filnam );
Expand All @@ -1147,7 +1154,6 @@ int tidyDocParseFile( TidyDocImpl* doc, ctmbstr filnam )

#if PRESERVE_FILE_TIMES
{
struct stat sbuf = { 0 };
/* get last modified time */
TidyClearMemory(&doc->filetimes, sizeof(doc->filetimes));
if (fin && cfgBool(doc, TidyKeepFileTimes) &&
Expand Down