Merge branch '2398_save_as_tilde_expand'
* 2398_save_as_tilde_expand: lib/lock.c: applied MC indentation policy. Expand tilde while locking and unlocking files. (edit_set_filename): expand tilde while setting file name. Ticket #2398: tilde is not treated as home directory in editor "Save As" dialog.
Этот коммит содержится в:
Коммит
f8a47dae4c
67
lib/lock.c
67
lib/lock.c
@ -54,6 +54,7 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
#include "lib/util.h" /* tilde_expand() */
|
||||
#include "lib/lock.h"
|
||||
|
||||
#include "src/wtools.h" /* query_dialog() */
|
||||
@ -61,7 +62,8 @@
|
||||
#define BUF_SIZE 255
|
||||
#define PID_BUF_SIZE 10
|
||||
|
||||
struct lock_s {
|
||||
struct lock_s
|
||||
{
|
||||
char *who;
|
||||
pid_t pid;
|
||||
};
|
||||
@ -78,11 +80,16 @@ lock_build_name (void)
|
||||
struct passwd *pw;
|
||||
|
||||
pw = getpwuid (getuid ());
|
||||
if (pw) user = pw->pw_name;
|
||||
if (!user) user = getenv ("USER");
|
||||
if (!user) user = getenv ("USERNAME");
|
||||
if (!user) user = getenv ("LOGNAME");
|
||||
if (!user) user = "";
|
||||
if (pw)
|
||||
user = pw->pw_name;
|
||||
if (!user)
|
||||
user = getenv ("USER");
|
||||
if (!user)
|
||||
user = getenv ("USERNAME");
|
||||
if (!user)
|
||||
user = getenv ("LOGNAME");
|
||||
if (!user)
|
||||
user = "";
|
||||
|
||||
/** \todo Use FQDN, no clean interface, so requires lot of code */
|
||||
if (gethostname (host, BUF_SIZE - 1) == -1)
|
||||
@ -165,30 +172,40 @@ lock_file (const char *fname)
|
||||
char *lockfname, *newlock, *msg, *lock;
|
||||
struct stat statbuf;
|
||||
struct lock_s *lockinfo;
|
||||
gboolean symlink_ok;
|
||||
|
||||
/* Just to be sure (and don't lock new file) */
|
||||
if (!fname || !*fname)
|
||||
if (fname == NULL || *fname == '\0')
|
||||
return 0;
|
||||
|
||||
fname = tilde_expand (fname);
|
||||
|
||||
/* Locking on VFS is not supported */
|
||||
if (!vfs_file_is_local (fname))
|
||||
{
|
||||
g_free (fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if already locked */
|
||||
lockfname = lock_build_symlink_name (fname);
|
||||
g_free (fname);
|
||||
if (lockfname == NULL)
|
||||
return 0;
|
||||
if (lstat (lockfname, &statbuf) == 0) {
|
||||
|
||||
if (lstat (lockfname, &statbuf) == 0)
|
||||
{
|
||||
lock = lock_get_info (lockfname);
|
||||
if (!lock) {
|
||||
if (lock == NULL)
|
||||
{
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
lockinfo = lock_extract_info (lock);
|
||||
|
||||
/* Check if locking process alive, ask user if required */
|
||||
if (!lockinfo->pid
|
||||
|| !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH)) {
|
||||
if (lockinfo->pid == 0 || !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH))
|
||||
{
|
||||
msg =
|
||||
g_strdup_printf (_
|
||||
("File \"%s\" is already being edited.\n"
|
||||
@ -196,8 +213,8 @@ lock_file (const char *fname)
|
||||
lockinfo->who, (int) lockinfo->pid);
|
||||
/* TODO: Implement "Abort" - needs to rewind undo stack */
|
||||
switch (query_dialog
|
||||
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"),
|
||||
_("&Ignore lock"))) {
|
||||
(_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"), _("&Ignore lock")))
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
@ -213,15 +230,11 @@ lock_file (const char *fname)
|
||||
|
||||
/* Create lock symlink */
|
||||
newlock = lock_build_name ();
|
||||
if (symlink (newlock, lockfname) == -1) {
|
||||
g_free (lockfname);
|
||||
symlink_ok = (symlink (newlock, lockfname) != -1);
|
||||
g_free (newlock);
|
||||
return 0;
|
||||
}
|
||||
g_free (lockfname);
|
||||
|
||||
g_free (lockfname);
|
||||
g_free (newlock);
|
||||
return 1;
|
||||
return symlink_ok ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Lowers file lock if possible
|
||||
@ -233,23 +246,29 @@ unlock_file (const char *fname)
|
||||
struct stat statbuf;
|
||||
|
||||
/* Just to be sure */
|
||||
if (!fname || !*fname)
|
||||
if (fname == NULL || *fname == '\0')
|
||||
return 0;
|
||||
|
||||
fname = tilde_expand (fname);
|
||||
lockfname = lock_build_symlink_name (fname);
|
||||
g_free (fname);
|
||||
|
||||
if (lockfname == NULL)
|
||||
return 0;
|
||||
|
||||
/* Check if lock exists */
|
||||
if (lstat (lockfname, &statbuf) == -1) {
|
||||
if (lstat (lockfname, &statbuf) == -1)
|
||||
{
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lock = lock_get_info (lockfname);
|
||||
if (lock) {
|
||||
if (lock != NULL)
|
||||
{
|
||||
/* Don't touch if lock is not ours */
|
||||
if (lock_extract_info (lock)->pid != getpid ()) {
|
||||
if (lock_extract_info (lock)->pid != getpid ())
|
||||
{
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "lib/skin.h"
|
||||
#include "lib/strutil.h" /* utf string functions */
|
||||
#include "lib/lock.h"
|
||||
#include "lib/util.h" /* tilde_expand() */
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
#include "src/history.h"
|
||||
@ -501,13 +502,15 @@ menu_save_mode_cmd (void)
|
||||
}
|
||||
|
||||
void
|
||||
edit_set_filename (WEdit * edit, const char *f)
|
||||
edit_set_filename (WEdit * edit, const char *name)
|
||||
{
|
||||
g_free (edit->filename);
|
||||
if (!f)
|
||||
f = "";
|
||||
edit->filename = g_strdup (f);
|
||||
if (edit->dir == NULL && !g_path_is_absolute (f))
|
||||
|
||||
if (name == NULL)
|
||||
name = "";
|
||||
|
||||
edit->filename = tilde_expand (name);
|
||||
if (edit->dir == NULL && !g_path_is_absolute (name))
|
||||
edit->dir = g_strdup (vfs_get_current_dir ());
|
||||
}
|
||||
|
||||
@ -557,8 +560,12 @@ edit_get_save_file_as (WEdit * edit)
|
||||
|
||||
if (quick_dialog (&Quick_options) != B_CANCEL)
|
||||
{
|
||||
char *fname;
|
||||
|
||||
edit->lb = cur_lb;
|
||||
return filename;
|
||||
fname = tilde_expand (filename);
|
||||
g_free (filename);
|
||||
return fname;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user