summaryrefslogtreecommitdiff
path: root/src/file.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-09-27 11:55:34 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-09-27 11:55:34 +0100
commite2720f1fbe09649e6da282cd33b9794867d3d0fb (patch)
treebb5f906151c28fc5fde6078b842a71c0ba4fc318 /src/file.cc
parent122a799ecb7dd1a6d6ff392ab9dc9d88fafad770 (diff)
Store timespec for buffer fs timestamps, not just time_t
time_t has a resolution of one second, which cause troubles when a file changes multiple time during that same second.
Diffstat (limited to 'src/file.cc')
-rw-r--r--src/file.cc16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/file.cc b/src/file.cc
index 2e67f872..ad526a93 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -180,13 +180,13 @@ Buffer* create_buffer_from_file(StringView filename)
throw file_access_error(real_filename, "is a directory");
if (S_ISFIFO(st.st_mode)) // Do not try to read fifos, use them as write only
return create_buffer_from_data({}, real_filename,
- Buffer::Flags::File, st.st_mtime);
+ Buffer::Flags::File, st.st_mtim);
const char* data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
auto unmap = on_scope_end([&]{ munmap((void*)data, st.st_size); });
return create_buffer_from_data({data, data + st.st_size}, real_filename,
- Buffer::Flags::File, st.st_mtime);
+ Buffer::Flags::File, st.st_mtim);
}
static void write(int fd, StringView data)
@@ -423,11 +423,11 @@ Vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
return res;
}
- typedef decltype(stat::st_mtime) TimeSpec;
+ typedef decltype(stat::st_mtim) TimeSpec;
struct CommandCache
{
- TimeSpec mtime = {};
+ TimeSpec mtim = {};
Vector<String> commands;
};
static UnorderedMap<String, CommandCache, MemoryDomain::Commands> command_cache;
@@ -442,7 +442,7 @@ Vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
continue;
auto& cache = command_cache[dirname];
- if (memcmp(&cache.mtime, &st.st_mtime, sizeof(TimeSpec)) != 0)
+ if (memcmp(&cache.mtim, &st.st_mtim, sizeof(TimeSpec)) != 0)
{
auto filter = [&](const dirent& entry) {
struct stat st;
@@ -457,7 +457,7 @@ Vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
};
cache.commands = list_files("", dirname, filter);
- memcpy(&cache.mtime, &st.st_mtime, sizeof(TimeSpec));
+ memcpy(&cache.mtim, &st.st_mtim, sizeof(TimeSpec));
}
for (auto& cmd : cache.commands)
{
@@ -471,12 +471,12 @@ Vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
return res;
}
-time_t get_fs_timestamp(StringView filename)
+timespec get_fs_timestamp(StringView filename)
{
struct stat st;
if (stat(filename.zstr(), &st) != 0)
return InvalidTime;
- return st.st_mtime;
+ return st.st_mtim;
}
String get_kak_binary_path()