1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
diff --git a/xbmc/filesystem/NFSFile.cpp b/xbmc/filesystem/NFSFile.cpp
index 2f9891529b11..becb40bb0aed 100644
--- a/xbmc/filesystem/NFSFile.cpp
+++ b/xbmc/filesystem/NFSFile.cpp
@@ -943,14 +943,10 @@ bool CNFSFile::OpenForWrite(const CURL& url, bool bOverWrite)
{
CLog::Log(LOGWARNING, "FileNFS::OpenForWrite() called with overwriting enabled! - {}",
filename);
- //create file with proper permissions
- ret = nfs_creat(m_pNfsContext, filename.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &m_pFileHandle);
- //if file was created the file handle isn't valid ... so close it and open later
- if(ret == 0)
- {
- nfs_close(m_pNfsContext,m_pFileHandle);
- m_pFileHandle = NULL;
- }
+ // nfs_open2 handles both creation and open atomically;
+ const int flags = bOverWrite ? O_CREAT | O_RDWR | O_EXCL : O_RDWR;
+ const int mode = bOverWrite ? S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH : 0;
+ ret = nfs_open2(m_pNfsContext, filename.c_str(), flags, mode, &m_pFileHandle);
}
ret = nfs_open(m_pNfsContext, filename.c_str(), O_RDWR, &m_pFileHandle);
--
2.53.0
|