mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 10:39:23 +01:00
storage: Add ability to preserve times
We use the mtime on the network profile as the 'Last Connected Time'. When we update any property and sync the file to disk, the mtime was not preserved (since we were creating a new temporary file instead of modifying the old one). This led to LastConnectedTime property change being emitted / updated incorrectly when a writable property on the KnownNetwork interface was updated.
This commit is contained in:
parent
759dbdd37f
commit
681172a999
@ -112,7 +112,7 @@ static void hotspot_network_sync(struct network_info *info,
|
|||||||
super);
|
super);
|
||||||
|
|
||||||
data = l_settings_to_data(settings, &length);
|
data = l_settings_to_data(settings, &length);
|
||||||
write_file(data, length, "%s", config->filename);
|
write_file(data, length, true, "%s", config->filename);
|
||||||
l_free(data);
|
l_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
|
|||||||
* file with a temporary name and when closed, it is renamed to the
|
* file with a temporary name and when closed, it is renamed to the
|
||||||
* specified name (@path_fmt+args).
|
* specified name (@path_fmt+args).
|
||||||
*/
|
*/
|
||||||
ssize_t write_file(const void *buffer, size_t len,
|
ssize_t write_file(const void *buffer, size_t len, bool preserve_times,
|
||||||
const char *path_fmt, ...)
|
const char *path_fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -150,6 +150,18 @@ ssize_t write_file(const void *buffer, size_t len,
|
|||||||
goto error_write;
|
goto error_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preserve_times) {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(path, &st) == 0) {
|
||||||
|
struct timespec times[2];
|
||||||
|
|
||||||
|
times[0] = st.st_atim;
|
||||||
|
times[1] = st.st_mtim;
|
||||||
|
utimensat(0, tmp_path, times, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now that the file contents are written, rename to the real
|
* Now that the file contents are written, rename to the real
|
||||||
* file name; this way we are uniquely sure that the whole
|
* file name; this way we are uniquely sure that the whole
|
||||||
@ -372,7 +384,7 @@ void storage_network_sync(enum security type, const char *ssid,
|
|||||||
|
|
||||||
path = storage_get_network_file_path(type, ssid);
|
path = storage_get_network_file_path(type, ssid);
|
||||||
data = l_settings_to_data(settings, &length);
|
data = l_settings_to_data(settings, &length);
|
||||||
write_file(data, length, "%s", path);
|
write_file(data, length, true, "%s", path);
|
||||||
l_free(data);
|
l_free(data);
|
||||||
l_free(path);
|
l_free(path);
|
||||||
}
|
}
|
||||||
@ -420,7 +432,7 @@ void storage_known_frequencies_sync(struct l_settings *known_freqs)
|
|||||||
known_freq_file_path = storage_get_path("/%s", KNOWN_FREQ_FILENAME);
|
known_freq_file_path = storage_get_path("/%s", KNOWN_FREQ_FILENAME);
|
||||||
|
|
||||||
data = l_settings_to_data(known_freqs, &len);
|
data = l_settings_to_data(known_freqs, &len);
|
||||||
write_file(data, len, "%s", known_freq_file_path);
|
write_file(data, len, false, "%s", known_freq_file_path);
|
||||||
l_free(data);
|
l_free(data);
|
||||||
|
|
||||||
l_free(known_freq_file_path);
|
l_free(known_freq_file_path);
|
||||||
|
@ -28,8 +28,9 @@ enum security;
|
|||||||
ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
|
ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
|
||||||
__attribute__((format(printf, 3, 4)));
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
|
ssize_t write_file(const void *buffer, size_t len, bool preserve_times,
|
||||||
__attribute__((format(printf, 3, 4)));
|
const char *path_fmt, ...)
|
||||||
|
__attribute__((format(printf, 4, 5)));
|
||||||
|
|
||||||
bool storage_create_dirs(void);
|
bool storage_create_dirs(void);
|
||||||
void storage_cleanup_dirs(void);
|
void storage_cleanup_dirs(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user