mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #3553 from ZyX-I/fix-xdg-2
Some more fixes to XDG code
This commit is contained in:
commit
d1cfaa0a55
@ -901,7 +901,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
again not rename the file.
|
again not rename the file.
|
||||||
|
|
||||||
*'backupdir'* *'bdir'*
|
*'backupdir'* *'bdir'*
|
||||||
'backupdir' 'bdir' string (default "$XDG_DATA_HOME/nvim/backup")
|
'backupdir' 'bdir' string (default ".,$XDG_DATA_HOME/nvim/backup")
|
||||||
global
|
global
|
||||||
List of directories for the backup file, separated with commas.
|
List of directories for the backup file, separated with commas.
|
||||||
- The backup file will be created in the first directory in the list
|
- The backup file will be created in the first directory in the list
|
||||||
@ -6695,8 +6695,8 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
global
|
global
|
||||||
Alias for 'term', see above.
|
Alias for 'term', see above.
|
||||||
|
|
||||||
*'undodir'* *'udir'*
|
*'undodir'* *'udir'* *E926*
|
||||||
'undodir' 'udir' string (default ".")
|
'undodir' 'udir' string (default "$XDG_DATA_HOME/nvim/undo")
|
||||||
global
|
global
|
||||||
{only when compiled with the |+persistent_undo| feature}
|
{only when compiled with the |+persistent_undo| feature}
|
||||||
List of directory names for undo files, separated with commas.
|
List of directory names for undo files, separated with commas.
|
||||||
@ -6705,8 +6705,10 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
"file.txt" is ".file.txt.un~".
|
"file.txt" is ".file.txt.un~".
|
||||||
For other directories the file name is the full path of the edited
|
For other directories the file name is the full path of the edited
|
||||||
file, with path separators replaced with "%".
|
file, with path separators replaced with "%".
|
||||||
When writing: The first directory that exists is used. "." always
|
When writing: The first directory that exists is used. "." always
|
||||||
works, no directories after "." will be used for writing.
|
works, no directories after "." will be used for writing. If none of
|
||||||
|
the directories exist Neovim will attempt to create last directory in
|
||||||
|
the list.
|
||||||
When reading all entries are tried to find an undo file. The first
|
When reading all entries are tried to find an undo file. The first
|
||||||
undo file that exists is used. When it cannot be read an error is
|
undo file that exists is used. When it cannot be read an error is
|
||||||
given, no further entry is used.
|
given, no further entry is used.
|
||||||
|
@ -16678,10 +16678,11 @@ static void f_undofile(typval_T *argvars, typval_T *rettv)
|
|||||||
/* If there is no file name there will be no undo file. */
|
/* If there is no file name there will be no undo file. */
|
||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
} else {
|
} else {
|
||||||
char_u *ffname = (char_u *)FullName_save((char *)fname, FALSE);
|
char *ffname = FullName_save((char *)fname, false);
|
||||||
|
|
||||||
if (ffname != NULL)
|
if (ffname != NULL) {
|
||||||
rettv->vval.v_string = u_get_undo_file_name(ffname, FALSE);
|
rettv->vval.v_string = (char_u *)u_get_undo_file_name(ffname, false);
|
||||||
|
}
|
||||||
xfree(ffname);
|
xfree(ffname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7193,7 +7193,7 @@ static void ex_wundo(exarg_T *eap)
|
|||||||
char_u hash[UNDO_HASH_SIZE];
|
char_u hash[UNDO_HASH_SIZE];
|
||||||
|
|
||||||
u_compute_hash(hash);
|
u_compute_hash(hash);
|
||||||
u_write_undo(eap->arg, eap->forceit, curbuf, hash);
|
u_write_undo((char *) eap->arg, eap->forceit, curbuf, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ex_rundo(exarg_T *eap)
|
static void ex_rundo(exarg_T *eap)
|
||||||
@ -7201,7 +7201,7 @@ static void ex_rundo(exarg_T *eap)
|
|||||||
char_u hash[UNDO_HASH_SIZE];
|
char_u hash[UNDO_HASH_SIZE];
|
||||||
|
|
||||||
u_compute_hash(hash);
|
u_compute_hash(hash);
|
||||||
u_read_undo(eap->arg, hash, NULL);
|
u_read_undo((char *) eap->arg, hash, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2990,7 +2990,7 @@ static void ml_lineadd(buf_T *buf, int count)
|
|||||||
* If it worked returns OK and the resolved link in "buf[MAXPATHL]".
|
* If it worked returns OK and the resolved link in "buf[MAXPATHL]".
|
||||||
* Otherwise returns FAIL.
|
* Otherwise returns FAIL.
|
||||||
*/
|
*/
|
||||||
int resolve_symlink(char_u *fname, char_u *buf)
|
int resolve_symlink(const char_u *fname, char_u *buf)
|
||||||
{
|
{
|
||||||
char_u tmp[MAXPATHL];
|
char_u tmp[MAXPATHL];
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -685,9 +685,13 @@ void set_init_1(void)
|
|||||||
#endif
|
#endif
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
char *backupdir = stdpaths_user_data_subpath("backup", 0);
|
||||||
|
const size_t backupdir_len = strlen(backupdir);
|
||||||
|
backupdir = xrealloc(backupdir, backupdir_len + 3);
|
||||||
|
memmove(backupdir + 2, backupdir, backupdir_len + 1);
|
||||||
|
memmove(backupdir, ".,", 2);
|
||||||
set_string_default("viewdir", stdpaths_user_data_subpath("view", 0), true);
|
set_string_default("viewdir", stdpaths_user_data_subpath("view", 0), true);
|
||||||
set_string_default("backupdir", stdpaths_user_data_subpath("backup", 0),
|
set_string_default("backupdir", backupdir, true);
|
||||||
true);
|
|
||||||
set_string_default("directory", stdpaths_user_data_subpath("swap", 2), true);
|
set_string_default("directory", stdpaths_user_data_subpath("swap", 2), true);
|
||||||
set_string_default("undodir", stdpaths_user_data_subpath("undo", 0), true);
|
set_string_default("undodir", stdpaths_user_data_subpath("undo", 0), true);
|
||||||
// Set default for &runtimepath. All necessary expansions are performed in
|
// Set default for &runtimepath. All necessary expansions are performed in
|
||||||
|
@ -25,7 +25,7 @@ static const char *const xdg_defaults[] = {
|
|||||||
[kXDGConfigHome] = "$LOCALAPPDATA\\nvim\\config",
|
[kXDGConfigHome] = "$LOCALAPPDATA\\nvim\\config",
|
||||||
[kXDGDataHome] = "$LOCALAPPDATA\\nvim\\data",
|
[kXDGDataHome] = "$LOCALAPPDATA\\nvim\\data",
|
||||||
[kXDGCacheHome] = "$LOCALAPPDATA\\nvim\\cache",
|
[kXDGCacheHome] = "$LOCALAPPDATA\\nvim\\cache",
|
||||||
[kXDGRuntimeDir] = "",
|
[kXDGRuntimeDir] = NULL,
|
||||||
[kXDGConfigDirs] = NULL,
|
[kXDGConfigDirs] = NULL,
|
||||||
[kXDGDataDirs] = NULL,
|
[kXDGDataDirs] = NULL,
|
||||||
#else
|
#else
|
||||||
@ -33,7 +33,7 @@ static const char *const xdg_defaults[] = {
|
|||||||
[kXDGConfigHome] = "~/.config",
|
[kXDGConfigHome] = "~/.config",
|
||||||
[kXDGDataHome] = "~/.local/share",
|
[kXDGDataHome] = "~/.local/share",
|
||||||
[kXDGCacheHome] = "~/.cache",
|
[kXDGCacheHome] = "~/.cache",
|
||||||
[kXDGRuntimeDir] = "",
|
[kXDGRuntimeDir] = NULL,
|
||||||
[kXDGConfigDirs] = "/etc/xdg/",
|
[kXDGConfigDirs] = "/etc/xdg/",
|
||||||
[kXDGDataDirs] = "/usr/local/share/:/usr/share/",
|
[kXDGDataDirs] = "/usr/local/share/:/usr/share/",
|
||||||
#endif
|
#endif
|
||||||
@ -82,7 +82,7 @@ static char *get_xdg_home(const XDGVarType idx)
|
|||||||
///
|
///
|
||||||
/// @return [allocated] `$XDG_CONFIG_HOME/nvim/{fname}`
|
/// @return [allocated] `$XDG_CONFIG_HOME/nvim/{fname}`
|
||||||
char *stdpaths_user_conf_subpath(const char *fname)
|
char *stdpaths_user_conf_subpath(const char *fname)
|
||||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
return concat_fnames_realloc(get_xdg_home(kXDGConfigHome), fname, true);
|
return concat_fnames_realloc(get_xdg_home(kXDGConfigHome), fname, true);
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ char *stdpaths_user_conf_subpath(const char *fname)
|
|||||||
/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`
|
/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`
|
||||||
char *stdpaths_user_data_subpath(const char *fname,
|
char *stdpaths_user_data_subpath(const char *fname,
|
||||||
const size_t trailing_pathseps)
|
const size_t trailing_pathseps)
|
||||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
char *ret = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true);
|
char *ret = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true);
|
||||||
if (trailing_pathseps) {
|
if (trailing_pathseps) {
|
||||||
|
176
src/nvim/undo.c
176
src/nvim/undo.c
@ -638,64 +638,89 @@ void u_compute_hash(char_u *hash)
|
|||||||
sha256_finish(&ctx, hash);
|
sha256_finish(&ctx, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Return an allocated string of the full path of the target undofile.
|
||||||
* Return an allocated string of the full path of the target undofile.
|
///
|
||||||
* When "reading" is TRUE find the file to read, go over all directories in
|
/// @param[in] buf_ffname Full file name for which undo file location should
|
||||||
* 'undodir'.
|
/// be found.
|
||||||
* When "reading" is FALSE use the first name where the directory exists.
|
/// @param[in] reading If true, find the file to read by traversing all of the
|
||||||
* Returns NULL when there is no place to write or no file to read.
|
/// directories in &undodir. If false use the first
|
||||||
*/
|
/// existing directory. If none of the directories in
|
||||||
char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
|
/// &undodir option exist then last directory in the list
|
||||||
|
/// will be automatically created.
|
||||||
|
///
|
||||||
|
/// @return [allocated] File name to read from/write to or NULL.
|
||||||
|
char *u_get_undo_file_name(const char *const buf_ffname, const bool reading)
|
||||||
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
char_u *dirp;
|
char *dirp;
|
||||||
char_u dir_name[IOSIZE + 1];
|
char dir_name[MAXPATHL + 1];
|
||||||
char_u *munged_name = NULL;
|
char *munged_name = NULL;
|
||||||
char_u *undo_file_name = NULL;
|
char *undo_file_name = NULL;
|
||||||
char_u *p;
|
const char *ffname = buf_ffname;
|
||||||
char_u *ffname = buf_ffname;
|
|
||||||
#ifdef HAVE_READLINK
|
#ifdef HAVE_READLINK
|
||||||
char_u fname_buf[MAXPATHL];
|
char fname_buf[MAXPATHL];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ffname == NULL)
|
if (ffname == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_READLINK
|
#ifdef HAVE_READLINK
|
||||||
/* Expand symlink in the file name, so that we put the undo file with the
|
// Expand symlink in the file name, so that we put the undo file with the
|
||||||
* actual file instead of with the symlink. */
|
// actual file instead of with the symlink.
|
||||||
if (resolve_symlink(ffname, fname_buf) == OK)
|
if (resolve_symlink((const char_u *)ffname, (char_u *)fname_buf) == OK) {
|
||||||
ffname = fname_buf;
|
ffname = fname_buf;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Loop over 'undodir'. When reading find the first file that exists.
|
// Loop over 'undodir'. When reading find the first file that exists.
|
||||||
* When not reading use the first directory that exists or ".". */
|
// When not reading use the first directory that exists or ".".
|
||||||
dirp = p_udir;
|
dirp = (char *) p_udir;
|
||||||
while (*dirp != NUL) {
|
while (*dirp != NUL) {
|
||||||
size_t dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ",");
|
size_t dir_len = copy_option_part((char_u **)&dirp, (char_u *)dir_name,
|
||||||
|
MAXPATHL, ",");
|
||||||
if (dir_len == 1 && dir_name[0] == '.') {
|
if (dir_len == 1 && dir_name[0] == '.') {
|
||||||
/* Use same directory as the ffname,
|
// Use same directory as the ffname,
|
||||||
* "dir/name" -> "dir/.name.un~" */
|
// "dir/name" -> "dir/.name.un~"
|
||||||
undo_file_name = vim_strnsave(ffname, STRLEN(ffname) + 5);
|
const size_t ffname_len = strlen(ffname);
|
||||||
p = path_tail(undo_file_name);
|
undo_file_name = xmalloc(ffname_len + 6);
|
||||||
memmove(p + 1, p, STRLEN(p) + 1);
|
memmove(undo_file_name, ffname, ffname_len + 1);
|
||||||
*p = '.';
|
char *const tail = (char *) path_tail((char_u *) undo_file_name);
|
||||||
STRCAT(p, ".un~");
|
const size_t tail_len = strlen(tail);
|
||||||
|
memmove(tail + 1, tail, tail_len + 1);
|
||||||
|
*tail = '.';
|
||||||
|
memmove(tail + tail_len + 1, ".un~", sizeof(".un~"));
|
||||||
} else {
|
} else {
|
||||||
dir_name[dir_len] = NUL;
|
dir_name[dir_len] = NUL;
|
||||||
if (os_isdir(dir_name)) {
|
bool has_directory = os_isdir((char_u *)dir_name);
|
||||||
if (munged_name == NULL) {
|
if (!has_directory && *dirp == NUL && !reading) {
|
||||||
munged_name = vim_strsave(ffname);
|
// Last directory in the list does not exist, create it.
|
||||||
for (p = munged_name; *p != NUL; mb_ptr_adv(p))
|
int ret;
|
||||||
if (vim_ispathsep(*p))
|
char *failed_dir;
|
||||||
*p = '%';
|
if ((ret = os_mkdir_recurse(dir_name, 0755, &failed_dir)) != 0) {
|
||||||
|
EMSG3(_("E926: Unable to create directory \"%s\" for undo file: %s"),
|
||||||
|
failed_dir, os_strerror(ret));
|
||||||
|
xfree(failed_dir);
|
||||||
|
} else {
|
||||||
|
has_directory = true;
|
||||||
}
|
}
|
||||||
undo_file_name = (char_u *)concat_fnames((char *)dir_name, (char *)munged_name, TRUE);
|
}
|
||||||
|
if (has_directory) {
|
||||||
|
if (munged_name == NULL) {
|
||||||
|
munged_name = xstrdup(ffname);
|
||||||
|
for (char *p = munged_name; *p != NUL; mb_ptr_adv(p)) {
|
||||||
|
if (vim_ispathsep(*p)) {
|
||||||
|
*p = '%';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
undo_file_name = concat_fnames(dir_name, munged_name, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When reading check if the file exists.
|
// When reading check if the file exists.
|
||||||
if (undo_file_name != NULL &&
|
if (undo_file_name != NULL
|
||||||
(!reading || os_file_exists(undo_file_name))) {
|
&& (!reading || os_file_exists((char_u *)undo_file_name))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xfree(undo_file_name);
|
xfree(undo_file_name);
|
||||||
@ -706,7 +731,13 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
|
|||||||
return undo_file_name;
|
return undo_file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void corruption_error(char *mesg, char_u *file_name)
|
/// Display an error for corrupted undo file
|
||||||
|
///
|
||||||
|
/// @param[in] mesg Identifier of the corruption kind.
|
||||||
|
/// @param[in] file_name File in which error occurred.
|
||||||
|
static void corruption_error(const char *const mesg,
|
||||||
|
const char *const file_name)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
EMSG3(_("E825: Corrupted undo file (%s): %s"), mesg, file_name);
|
EMSG3(_("E825: Corrupted undo file (%s): %s"), mesg, file_name);
|
||||||
}
|
}
|
||||||
@ -821,7 +852,8 @@ static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u_header_T *unserialize_uhp(bufinfo_T *bi, char_u *file_name)
|
static u_header_T *unserialize_uhp(bufinfo_T *bi,
|
||||||
|
const char *file_name)
|
||||||
{
|
{
|
||||||
u_header_T *uhp = xmalloc(sizeof(u_header_T));
|
u_header_T *uhp = xmalloc(sizeof(u_header_T));
|
||||||
memset(uhp, 0, sizeof(u_header_T));
|
memset(uhp, 0, sizeof(u_header_T));
|
||||||
@ -918,7 +950,8 @@ static bool serialize_uep(bufinfo_T *bi, u_entry_T *uep)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error, char_u *file_name)
|
static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error,
|
||||||
|
const char *file_name)
|
||||||
{
|
{
|
||||||
u_entry_T *uep = xmalloc(sizeof(u_entry_T));
|
u_entry_T *uep = xmalloc(sizeof(u_entry_T));
|
||||||
memset(uep, 0, sizeof(u_entry_T));
|
memset(uep, 0, sizeof(u_entry_T));
|
||||||
@ -1000,19 +1033,20 @@ static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info)
|
|||||||
info->vi_curswant = undo_read_4c(bi);
|
info->vi_curswant = undo_read_4c(bi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Write the undo tree in an undo file.
|
||||||
* Write the undo tree in an undo file.
|
///
|
||||||
* When "name" is not NULL, use it as the name of the undo file.
|
/// @param[in] name Name of the undo file or NULL if this function needs to
|
||||||
* Otherwise use buf->b_ffname to generate the undo file name.
|
/// generate the undo file name based on buf->b_ffname.
|
||||||
* "buf" must never be null, buf->b_ffname is used to obtain the original file
|
/// @param[in] forceit True for `:wundo!`, false otherwise.
|
||||||
* permissions.
|
/// @param[in] buf Buffer for which undo file is written.
|
||||||
* "forceit" is TRUE for ":wundo!", FALSE otherwise.
|
/// @param[in] hash Hash value of the buffer text. Must have #UNDO_HASH_SIZE
|
||||||
* "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
|
/// size.
|
||||||
*/
|
void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
|
||||||
void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
char_u *const hash)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(3, 4)
|
||||||
{
|
{
|
||||||
u_header_T *uhp;
|
u_header_T *uhp;
|
||||||
char_u *file_name;
|
char *file_name;
|
||||||
int mark;
|
int mark;
|
||||||
#ifdef U_DEBUG
|
#ifdef U_DEBUG
|
||||||
int headers_written = 0;
|
int headers_written = 0;
|
||||||
@ -1024,7 +1058,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
bufinfo_T bi;
|
bufinfo_T bi;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
file_name = u_get_undo_file_name(buf->b_ffname, FALSE);
|
file_name = u_get_undo_file_name((char *) buf->b_ffname, false);
|
||||||
if (file_name == NULL) {
|
if (file_name == NULL) {
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
verbose_enter();
|
verbose_enter();
|
||||||
@ -1033,8 +1067,9 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
file_name = name;
|
file_name = (char *) name;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decide about the permission to use for the undo file. If the buffer
|
* Decide about the permission to use for the undo file. If the buffer
|
||||||
@ -1054,10 +1089,10 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
|
|
||||||
/* If the undo file already exists, verify that it actually is an undo
|
/* If the undo file already exists, verify that it actually is an undo
|
||||||
* file, and delete it. */
|
* file, and delete it. */
|
||||||
if (os_file_exists(file_name)) {
|
if (os_file_exists((char_u *)file_name)) {
|
||||||
if (name == NULL || !forceit) {
|
if (name == NULL || !forceit) {
|
||||||
/* Check we can read it and it's an undo file. */
|
/* Check we can read it and it's an undo file. */
|
||||||
fd = os_open((char *)file_name, O_RDONLY, 0);
|
fd = os_open(file_name, O_RDONLY, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (name != NULL || p_verbose > 0) {
|
if (name != NULL || p_verbose > 0) {
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
@ -1086,7 +1121,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os_remove((char *)file_name);
|
os_remove(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there is no undo information at all, quit here after deleting any
|
/* If there is no undo information at all, quit here after deleting any
|
||||||
@ -1097,13 +1132,12 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = os_open((char *)file_name,
|
fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
|
||||||
O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
EMSG2(_(e_not_open), file_name);
|
EMSG2(_(e_not_open), file_name);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
(void)os_setperm(file_name, perm);
|
(void)os_setperm((char_u *)file_name, perm);
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
verbose_enter();
|
verbose_enter();
|
||||||
smsg(_("Writing undo file: %s"), file_name);
|
smsg(_("Writing undo file: %s"), file_name);
|
||||||
@ -1125,10 +1159,10 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
FileInfo file_info_new;
|
FileInfo file_info_new;
|
||||||
if (buf->b_ffname != NULL
|
if (buf->b_ffname != NULL
|
||||||
&& os_fileinfo((char *)buf->b_ffname, &file_info_old)
|
&& os_fileinfo((char *)buf->b_ffname, &file_info_old)
|
||||||
&& os_fileinfo((char *)file_name, &file_info_new)
|
&& os_fileinfo(file_name, &file_info_new)
|
||||||
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
|
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
|
||||||
&& os_fchown(fd, (uv_uid_t)-1, (uv_gid_t)file_info_old.stat.st_gid)) {
|
&& os_fchown(fd, (uv_uid_t)-1, (uv_gid_t)file_info_old.stat.st_gid)) {
|
||||||
os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
|
os_setperm((char_u *)file_name, (perm & 0707) | ((perm & 07) << 3));
|
||||||
}
|
}
|
||||||
# ifdef HAVE_SELINUX
|
# ifdef HAVE_SELINUX
|
||||||
if (buf->b_ffname != NULL)
|
if (buf->b_ffname != NULL)
|
||||||
@ -1140,7 +1174,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
EMSG2(_(e_not_open), file_name);
|
EMSG2(_(e_not_open), file_name);
|
||||||
close(fd);
|
close(fd);
|
||||||
os_remove((char *)file_name);
|
os_remove(file_name);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1209,7 +1243,7 @@ write_error:
|
|||||||
|
|
||||||
/* For systems that support ACL: get the ACL from the original file. */
|
/* For systems that support ACL: get the ACL from the original file. */
|
||||||
acl = mch_get_acl(buf->b_ffname);
|
acl = mch_get_acl(buf->b_ffname);
|
||||||
mch_set_acl(file_name, acl);
|
mch_set_acl((char_u *)file_name, acl);
|
||||||
mch_free_acl(acl);
|
mch_free_acl(acl);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1224,15 +1258,15 @@ theend:
|
|||||||
/// a bit more verbose.
|
/// a bit more verbose.
|
||||||
/// Otherwise use curbuf->b_ffname to generate the undo file name.
|
/// Otherwise use curbuf->b_ffname to generate the undo file name.
|
||||||
/// "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
|
/// "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
|
||||||
void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
void u_read_undo(char *name, char_u *hash, char_u *orig_name)
|
||||||
FUNC_ATTR_NONNULL_ARG(2)
|
FUNC_ATTR_NONNULL_ARG(2)
|
||||||
{
|
{
|
||||||
u_header_T **uhp_table = NULL;
|
u_header_T **uhp_table = NULL;
|
||||||
char_u *line_ptr = NULL;
|
char_u *line_ptr = NULL;
|
||||||
|
|
||||||
char_u *file_name;
|
char *file_name;
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE);
|
file_name = u_get_undo_file_name((char *) curbuf->b_ffname, true);
|
||||||
if (file_name == NULL) {
|
if (file_name == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1256,7 +1290,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
file_name = name;
|
file_name = (char *) name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
@ -1265,7 +1299,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
|||||||
verbose_leave();
|
verbose_leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp = mch_fopen((char *)file_name, "r");
|
FILE *fp = mch_fopen(file_name, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
if (name != NULL || p_verbose > 0) {
|
if (name != NULL || p_verbose > 0) {
|
||||||
EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name);
|
EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user