aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/history.cpp
diff options
context:
space:
mode:
authorGravatar Jeff Kowalski <jeff.kowalski@gmail.com>2015-09-18 20:47:38 -0700
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-10-16 07:40:04 +0800
commitb13f0701a45f45568060d7dd7a5fed1052e9be60 (patch)
tree24cac88123bff414b110a64e211a0ae6705d25d6 /src/history.cpp
parent4c2cc384d28f039a96d1ec60521deacdbfe220a4 (diff)
Migrate fish_history from config to data dir
New implementation of migration code within the history_t class will copy the contents of the old fish_history found in the config directory to its new location in the data directory. The old file is left intact. This is done only in the event that a fish_history is not already found in the data directory ($XDG_DATA_HOME/fish or ~/.local/share/fish).
Diffstat (limited to 'src/history.cpp')
-rw-r--r--src/history.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/history.cpp b/src/history.cpp
index 6b458212..96ff3db8 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -1664,6 +1664,53 @@ bool history_t::is_empty(void)
return empty;
}
+
+/* Populates from older location (in config path, rather than data path)
+ This is accomplished by clearing ourselves, and copying the contents of
+ the old history file to the new history file. The new contents will
+ automatically be re-mapped later.
+*/
+void history_t::populate_from_config_path()
+{
+ wcstring old_file;
+ if (path_get_config(old_file)) {
+ old_file.append(L"/");
+ old_file.append(name);
+ old_file.append(L"_history");
+ int src_fd = wopen_cloexec(old_file, O_RDONLY, 0);
+ if (src_fd != -1)
+ {
+ wcstring new_file;
+ history_filename(new_file, L"");
+
+ /* clear must come after we've retrieved the new_file name,
+ and before we open destination file descriptor,
+ since it destroys the name and the file */
+ this->clear();
+
+ int dst_fd = wopen_cloexec(new_file, O_WRONLY | O_CREAT, 0644);
+
+ char buf[BUFSIZ];
+ size_t size;
+ while ((size = read(src_fd, buf, BUFSIZ)) > 0) {
+ ssize_t written = write(dst_fd, buf, size);
+ if (written == -1) {
+ /*
+ This message does not have high enough priority to
+ be shown by default.
+ */
+ debug(2, L"Error when writing history file");
+ break;
+ }
+ }
+
+ close(src_fd);
+ close(dst_fd);
+ }
+ }
+}
+
+
/* Indicate whether we ought to import the bash history file into fish */
static bool should_import_bash_history_line(const std::string &line)
{