summaryrefslogtreecommitdiff
path: root/zen/file_io.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-07-22 11:37:03 -0400
committerB Stack <bgstack15@gmail.com>2020-07-22 11:37:03 -0400
commitc95b3937fef3e2c63768f1b3b1dc2c898f23d91d (patch)
tree10260e25ae905564f7978b83fc4e316670f987c6 /zen/file_io.cpp
parentMerge branch '10.25' into 'master' (diff)
downloadFreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.gz
FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.bz2
FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.zip
add upstream 11.0
Diffstat (limited to 'zen/file_io.cpp')
-rw-r--r--zen/file_io.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/zen/file_io.cpp b/zen/file_io.cpp
index 942f367f..80a83724 100644
--- a/zen/file_io.cpp
+++ b/zen/file_io.cpp
@@ -46,23 +46,21 @@ namespace
{
FileBase::FileHandle openHandleForRead(const Zstring& filePath) //throw FileError, ErrorFileLocked
{
- //- "filePath" could be a named pipe which *blocks* forever for open()!
- //- open() with O_NONBLOCK avoids the block, but opens successfully
- //- create sample pipe: "sudo mkfifo named_pipe"
+ //caveat: check for file types that block during open(): character device, block device, named pipe
struct ::stat fileInfo = {};
if (::stat(filePath.c_str(), &fileInfo) == 0) //follows symlinks
{
if (!S_ISREG(fileInfo.st_mode) &&
- !S_ISLNK(fileInfo.st_mode) &&
- !S_ISDIR(fileInfo.st_mode))
+ !S_ISDIR(fileInfo.st_mode) && //open() will fail with "EISDIR: Is a directory" => nice
+ !S_ISLNK(fileInfo.st_mode)) //?? shouldn't be possible after successful stat()
{
const std::wstring typeName = [m = fileInfo.st_mode]
{
std::wstring name =
- S_ISCHR (m) ? L"character device" :
- S_ISBLK (m) ? L"block device" :
+ S_ISCHR (m) ? L"character device" : //e.g. /dev/null
+ S_ISBLK (m) ? L"block device" : //e.g. /dev/sda1
S_ISFIFO(m) ? L"FIFO, named pipe" :
- S_ISSOCK(m) ? L"socket" : L"";
+ S_ISSOCK(m) ? L"socket" : L""; //doesn't block but open() error is unclear: "ENXIO: No such device or address"
if (!name.empty())
name += L", ";
return name + printNumber<std::wstring>(L"0%06o", m & S_IFMT);
bgstack15