fs/smartfs/smartfs_smart.c: Fix O_CREAT without O_TRUNC truncating existing file. Also nothing in POSIX says that O_APPEND should prevent O_TRUNC.

This commit is contained in:
Juha Niskanen
2019-11-05 07:28:24 -06:00
committed by Gregory Nutt
parent 0154126c01
commit 3268eb882e
+4 -8
View File
@@ -260,15 +260,12 @@ static int smartfs_open(FAR struct file *filep, const char *relpath,
/* TODO: Test open mode based on the file mode */ /* TODO: Test open mode based on the file mode */
/* The file exists. Check if we are opening it for O_CREAT or /* If O_TRUNC is specified and the file is opened for writing,
* O_TRUNC mode and delete the sector chain if we are. * then truncate the file. This operation requires that the file
* is writeable. O_TRUNC without write access is ignored.
*/ */
if ((oflags & (O_CREAT | O_TRUNC)) != 0) if ((oflags & (O_TRUNC | O_WROK)) == (O_TRUNC | O_WROK))
{
/* Don't truncate if open for APPEND */
if (!(oflags & O_APPEND))
{ {
/* Truncate the file as part of the open */ /* Truncate the file as part of the open */
@@ -279,7 +276,6 @@ static int smartfs_open(FAR struct file *filep, const char *relpath,
} }
} }
} }
}
else if (ret == -ENOENT) else if (ret == -ENOENT)
{ {
/* The file does not exist. Were we asked to create it? */ /* The file does not exist. Were we asked to create it? */