vim-patch:8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD (#20967)

Problem:    Some tests fail on Cirrus CI and/or with FreeBSD.
Solution:   Make 'backupskip' empty. Do not run tests as root. Check for
            directory when using viminfo. (Ozaki Kiichi, closes vim/vim#6596)

b86abadf87
This commit is contained in:
zeertzjq
2022-11-06 22:13:36 +08:00
committed by GitHub
parent da0fb43849
commit 728c69bc8d
4 changed files with 58 additions and 53 deletions

View File

@@ -3079,32 +3079,37 @@ shada_write_file_nomerge: {}
sd_reader.close(&sd_reader);
bool did_remove = false;
if (sw_ret == kSDWriteSuccessful) {
#ifdef UNIX
// For Unix we check the owner of the file. It's not very nice to
// overwrite a users viminfo file after a "su root", with a
// viminfo file that the user can't read.
FileInfo old_info;
if (os_fileinfo(fname, &old_info)) {
if (getuid() == ROOT_UID) {
if (old_info.stat.st_uid != ROOT_UID
|| old_info.stat.st_gid != getgid()) {
const uv_uid_t old_uid = (uv_uid_t)old_info.stat.st_uid;
const uv_gid_t old_gid = (uv_gid_t)old_info.stat.st_gid;
const int fchown_ret = os_fchown(file_fd(sd_writer.cookie),
old_uid, old_gid);
if (fchown_ret != 0) {
semsg(_(RNERR "Failed setting uid and gid for file %s: %s"),
tempname, os_strerror(fchown_ret));
goto shada_write_file_did_not_remove;
}
if (!os_fileinfo(fname, &old_info)
|| S_ISDIR(old_info.stat.st_mode)
#ifdef UNIX
// For Unix we check the owner of the file. It's not very nice
// to overwrite a user's viminfo file after a "su root", with a
// viminfo file that the user can't read.
|| (getuid() != ROOT_UID
&& !(old_info.stat.st_uid == getuid()
? (old_info.stat.st_mode & 0200)
: (old_info.stat.st_gid == getgid()
? (old_info.stat.st_mode & 0020)
: (old_info.stat.st_mode & 0002))))
#endif
) {
semsg(_("E137: ShaDa file is not writable: %s"), fname);
goto shada_write_file_did_not_remove;
}
#ifdef UNIX
if (getuid() == ROOT_UID) {
if (old_info.stat.st_uid != ROOT_UID
|| old_info.stat.st_gid != getgid()) {
const uv_uid_t old_uid = (uv_uid_t)old_info.stat.st_uid;
const uv_gid_t old_gid = (uv_gid_t)old_info.stat.st_gid;
const int fchown_ret = os_fchown(file_fd(sd_writer.cookie),
old_uid, old_gid);
if (fchown_ret != 0) {
semsg(_(RNERR "Failed setting uid and gid for file %s: %s"),
tempname, os_strerror(fchown_ret));
goto shada_write_file_did_not_remove;
}
} else if (!(old_info.stat.st_uid == getuid()
? (old_info.stat.st_mode & 0200)
: (old_info.stat.st_gid == getgid()
? (old_info.stat.st_mode & 0020)
: (old_info.stat.st_mode & 0002)))) {
semsg(_("E137: ShaDa file is not writable: %s"), fname);
goto shada_write_file_did_not_remove;
}
}
#endif
@@ -3125,9 +3130,7 @@ shada_write_file_nomerge: {}
}
}
if (!did_remove) {
#ifdef UNIX
shada_write_file_did_not_remove:
#endif
semsg(_(RNERR "Do not forget to remove %s or rename it manually to %s."),
tempname, fname);
}