Пример #1
0
static int
rename_wrapper (char const *oldfilename, char const *newfilename)
{
	int result = g_rename (oldfilename, newfilename);
	if (!result)
		goto done;

#ifdef HAVE_SYS_STATFS_H
#ifdef HAVE_2ARG_STATFS
	/* The FUSE file system does not unlink the target.  */
	if (errno == EPERM) {
		int save_errno = errno;
		struct statfs buf;
		if (statfs (newfilename, &buf) == 0 &&
		    memcmp (&buf.f_type, "FUse", 4) == 0)
			goto unlink_and_retry;
		errno = save_errno;
	}
#endif
#endif

#ifdef G_OS_WIN32
	/* Win32's rename does not unlink the target.  */
	goto unlink_and_retry;
#endif

done:
	return result;

unlink_and_retry:
	(void)g_unlink (newfilename);
	result = g_rename (oldfilename, newfilename);
	goto done;
}
Пример #2
0
int  ug_rename (const gchar *old_filename, const gchar *new_filename)
{
	if (g_get_filename_charsets (NULL))
		return g_rename (old_filename, new_filename);
	else {
		gchar *cp_old_filename = g_filename_from_utf8 (old_filename, -1, NULL, NULL, NULL);
		gchar *cp_new_filename = g_filename_from_utf8 (new_filename, -1, NULL, NULL, NULL);
		int save_errno;
		int retval;

		if (cp_old_filename == NULL || cp_new_filename == NULL) {
			g_free (cp_old_filename);
			g_free (cp_new_filename);
			errno = EINVAL;
			return -1;
		}

		retval = g_rename (cp_old_filename, cp_new_filename);
		save_errno = errno;

		g_free (cp_old_filename);
		g_free (cp_new_filename);

		errno = save_errno;
		return retval;
	}
}
Пример #3
0
/** Intelligently move content of tmp_out_repo to in_repo
 * (the repomd.xml is moved as a last file)
 */
static gboolean
move_results(const gchar *tmp_out_repo,
             const gchar *in_repo,
             GError **err)
{
    _cleanup_dir_close_ GDir *dirp = NULL;
    _cleanup_error_free_ GError *tmp_err = NULL;

    // Open the source directory
    dirp = g_dir_open(tmp_out_repo, 0, &tmp_err);
    if (!dirp) {
        g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
                    "Cannot open dir %s: %s",
                    tmp_out_repo, tmp_err->message);
        return FALSE;
    }

    // Iterate over its content
    const gchar *filename;
    while ((filename = g_dir_read_name(dirp))) {
        _cleanup_free_ gchar *src_path = NULL;
        _cleanup_free_ gchar *dst_path = NULL;

        // Skip repomd.xml
        if (!g_strcmp0(filename, "repomd.xml"))
            continue;

        // Get full src path
        src_path = g_build_filename(tmp_out_repo, filename, NULL);

        // Prepare full dst path
        dst_path = g_build_filename(in_repo, filename, NULL);

        // Move the file
        if (g_rename(src_path, dst_path) == -1) {
            g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
                        "Cannot move: %s to: %s: %s",
                        src_path, dst_path, g_strerror(errno));
            return FALSE;
        }
    }

    // The last step - move of the repomd.xml
    {
        _cleanup_free_ gchar *src_path = NULL;
        _cleanup_free_ gchar *dst_path = NULL;
        src_path = g_build_filename(tmp_out_repo, "repomd.xml", NULL);
        dst_path = g_build_filename(in_repo, "repomd.xml", NULL);
        if (g_rename(src_path, dst_path) == -1) {
            g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
                        "Cannot move: %s to: %s: %s",
                        src_path, dst_path, g_strerror(errno));
            return FALSE;
        }
    }

    return TRUE;
}
Пример #4
0
static void
grl_magnatune_source_init(GrlMagnatuneSource *source)
{
  gint ret;
  gchar *path;
  gchar *db_path;
  gchar *crc_path;
  gchar *new_db_path;
  gchar *new_crc_path;

  GRL_DEBUG("magnatune_source_init");

  source->priv = GRL_MAGNATUNE_GET_PRIVATE(source);
  source->priv->db = NULL;

  path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", NULL);
  db_path = g_build_filename(path, GRL_SQL_DB, NULL);
  crc_path = g_build_filename(path, GRL_SQL_CRC, NULL);
  new_db_path = g_build_filename(path, GRL_SQL_NEW_DB, NULL);
  new_crc_path = g_build_filename(path, GRL_SQL_NEW_CRC, NULL);

  if(!g_file_test(path, G_FILE_TEST_IS_DIR)) {
    g_mkdir_with_parents(path, 0775);
  }

  if (g_file_test(db_path, G_FILE_TEST_EXISTS) == TRUE) {
    if (g_file_test(new_db_path, G_FILE_TEST_EXISTS) == TRUE
        && g_rename(new_db_path, db_path) == 0) {
        GRL_DEBUG("New database in use.");
    }

    if (g_file_test(new_crc_path, G_FILE_TEST_EXISTS) == TRUE
        && g_rename(new_crc_path, crc_path) == 0) {
        GRL_DEBUG("New crc file in use.");
    }

    GRL_DEBUG("Opening database connection.");
    ret = sqlite3_open(db_path, &source->priv->db);
    if (ret != SQLITE_OK) {
      GRL_WARNING("Failed to open database '%s': %s",
                  db_path,
                  sqlite3_errmsg(source->priv->db));
      sqlite3_close(source->priv->db);
      source->priv->db = NULL;
    }
  } else {
    GRL_DEBUG("No database was found. Download when user interact.");
  }

  g_free(new_crc_path);
  g_free(new_db_path);
  g_free(crc_path);
  g_free(db_path);
  g_free(path);
}
Пример #5
0
/**
 * fm_folder_config_save_cache
 *
 * Saves current data into the cache file.
 *
 * Since: 1.2.0
 */
void fm_folder_config_save_cache(void)
{
    char *out;
    char *path, *path2, *path3;
    GError *error = NULL;
    gsize len;

    G_LOCK(cache);
    /* if per-directory cache was changed since last invocation then save it */
    if (fc_cache_changed && (out = g_key_file_to_data(fc_cache, &len, NULL)))
    {
        /* FIXME: create dir */
        /* create temp file with settings */
        path = g_build_filename(g_get_user_config_dir(), "libfm/dir-settings.conf", NULL);
        path2 = g_build_filename(g_get_user_config_dir(), "libfm/dir-settings.tmp", NULL);
        path3 = g_build_filename(g_get_user_config_dir(), "libfm/dir-settings.backup", NULL);
        /* do safe replace now, the file is important enough to be lost */
        if (g_file_set_contents(path2, out, len, &error))
        {
            /* backup old cache file */
            g_unlink(path3);
            if (!g_file_test(path, G_FILE_TEST_EXISTS) ||
                g_rename(path, path3) == 0)
            {
                /* rename temp file */
                if (g_rename(path2, path) == 0)
                {
                    /* success! remove the old cache file */
                    g_unlink(path3);
                    /* reset the 'changed' flag */
                    fc_cache_changed = FALSE;
                }
                else
                    g_warning("cannot rename %s to %s: %s", path2, path,
                              g_strerror(errno));
            }
            else
                g_warning("cannot rename %s to %s: %s", path, path3,
                          g_strerror(errno));
        }
        else
        {
            g_warning("cannot save %s: %s", path2, error->message);
            g_error_free(error);
        }
        g_free(path);
        g_free(path2);
        g_free(path3);
        g_free(out);
    }
    G_UNLOCK(cache);
}
Пример #6
0
static void
rename_mbox_dir (ESource *mbox_source,
                 const gchar *mail_data_dir)
{
	gchar *old_mail_dir;
	gchar *new_mail_dir;
	gboolean need_rename;
	const gchar *mbox_uid;

	mbox_uid = e_source_get_uid (mbox_source);

	old_mail_dir = g_build_filename (mail_data_dir, "local", NULL);
	new_mail_dir = g_build_filename (mail_data_dir, mbox_uid, NULL);

	/* Rename if old directory exists and new directory does not. */
	need_rename =
		g_file_test (old_mail_dir, G_FILE_TEST_EXISTS) &&
		!g_file_test (new_mail_dir, G_FILE_TEST_EXISTS);

	if (need_rename) {
		if (g_rename (old_mail_dir, new_mail_dir) == -1)
			g_warning (
				"%s: Failed to rename '%s' to '%s': %s",
				G_STRFUNC, old_mail_dir, new_mail_dir, g_strerror (errno));
	}

	g_free (old_mail_dir);
	g_free (new_mail_dir);
}
Пример #7
0
Файл: log.c Проект: Mortal/claws
void set_log_file(LogInstance instance, const gchar *filename)
{
	gchar *fullname = NULL;
	if (log_fp[instance])
		return;

	if (!g_path_is_absolute(filename)) {
		fullname = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
					filename, NULL);
	} else {
		fullname = g_strdup(filename);
	}
	/* backup old logfile if existing */
	if (is_file_exist(fullname)) {
		gchar *backupname;
		
		backupname = g_strconcat(fullname, ".bak", NULL);
		claws_unlink(backupname);
		if (g_rename(fullname, backupname) < 0)
			FILE_OP_ERROR(fullname, "rename");
		g_free(backupname);
	}

	log_fp[instance] = g_fopen(fullname, "wb");
	if (!log_fp[instance]) {
		FILE_OP_ERROR(fullname, "fopen");
		log_filename[instance] = NULL;
		g_free(fullname);
		return;
	}
	log_filename[instance] = g_strdup(fullname);
	log_size[instance] = 0;
	g_free(fullname);
}
Пример #8
0
int log_nsp_stop(void)
{
	char *r;
	char * ifn2;

	if (!ifn || ! ofn)
	{
		return 0;
	}

	r = strrchr(ifn, '.');
	if (r)
	{
		*r = '\0';
	}

	nsp_decomp(ifn);
	ifn2 = g_strconcat(ifn, ".pkt", NULL);
	g_free(ifn);
	ifn = ifn2;

	g_unlink(ofn);
	if (g_rename(ifn, ofn) < 0)
	{
		fprintf(stderr, "Failed to rename output file\n");
	}

	g_free(ifn); 
	ifn = NULL;
	g_free(ofn); 
	ofn = NULL;

	return 0;
}
Пример #9
0
static void
migrate_profile (const char *old_dir,
                 const char *new_dir)
{
  char *parent_dir;
  char *updated;
  const char *message;

  if (g_file_test (new_dir, G_FILE_TEST_EXISTS) ||
      !g_file_test (old_dir, G_FILE_TEST_IS_DIR))
    return;

  /* Test if we already attempted to migrate first. */
  updated = g_build_filename (old_dir, "DEPRECATED-DIRECTORY", NULL);
  message = _("Epiphany 3.6 deprecated this directory and tried migrating "
              "this configuration to ~/.config/epiphany");

  parent_dir = g_path_get_dirname (new_dir);
  if (g_mkdir_with_parents (parent_dir, 0700) == 0) {
    int fd, res;

    /* rename() works fine if the destination directory is empty. */
    res = g_rename (old_dir, new_dir);
    if (res == -1 && !g_file_test (updated, G_FILE_TEST_EXISTS)) {
      fd = g_creat (updated, 0600);
      if (fd != -1) {
        res = write (fd, message, strlen (message));
        close (fd);
      }
    }
  }

  g_free (parent_dir);
  g_free (updated);
}
Пример #10
0
static gboolean
move_and_symlink_dir(const char *path, const char *basename, const char *old_base, const char *new_base, const char *relative)
{
    char *new_name = g_build_filename(new_base, basename, NULL);
#ifndef _WIN32
    char *old_name;
#endif
    if (g_rename(path, new_name))
    {
        purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                           path, new_name, g_strerror(errno));
        g_free(new_name);
        return FALSE;
    }
    g_free(new_name);

#ifndef _WIN32
    /* NOTE: This new_name is relative. */
    new_name = g_build_filename(relative, basename, NULL);
    old_name = g_build_filename(old_base, basename, NULL);
    if (symlink(new_name, old_name))
    {
        purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
                             old_name, new_name, g_strerror(errno));
    }
    g_free(old_name);
    g_free(new_name);
#endif

    return TRUE;
}
Пример #11
0
void
MoonInstallerService::UpdaterCompleted ()
{
	char *content, *path, *tmp;
	char *xap;
	int err = 0;
	gsize size;
	gsize xap_len;
	FILE *fp;
	
	path = g_build_filename (GetBaseInstallDir (), app->uid, "Application.xap", NULL);
	
	// check that the xap has changed...
	if (g_file_get_contents (path, &content, &size, NULL)) {
		if (g_file_get_contents (request->GetFilename (), &xap, &xap_len, NULL)) {
			if (xap_len == size && !memcmp (xap, content, size)) {
				// no change to the xap
				completed (false, NULL, user_data);
				CloseDownloader (false);
				g_free (content);
				g_free (xap);
				g_free (path);
				return;
			}
			g_free (xap);
		}
		g_free (content);
	}
	
	tmp = g_strdup_printf ("%s.tmp", path);
	
	if ((fp = fopen (tmp, "wb"))) {
		// write to the temporary file
		if (CopyFileTo (request->GetFilename (), fileno (fp)))
			err = ferror (fp);
		fclose (fp);
		
		if (err == 0) {
			// rename the temp file to the actual file
			if (g_rename (tmp, path) == -1)
				err = errno;
		}
	} else {
		err = errno;
	}
	
	g_free (path);
	g_free (tmp);
	
	if (err == 0) {
		// update the app's mtime
		// FIXME: get the Last-Modified: header from the downloader?
		app->mtime = time (NULL);
		db->SyncAppRecord (app);
	}
	
	completed (err == 0, err ? g_strerror (err) : NULL, user_data);
	
	CloseDownloader (false);
}
Пример #12
0
/**
 * Creates the directory if it does not exist.
 * Returns newly allocated dir name, NULL if an error occurred.
 */
static gchar *
make_config_dir (void)
{
	gchar *dir = NULL;
	
	make_path (g_get_user_config_dir ());
	
	dir = g_build_filename (g_get_user_config_dir (), PACKAGE, NULL);
	
	if (!g_file_test (dir, G_FILE_TEST_EXISTS))
	{
		gchar *olddir;
		
		/* For backwards-compatibility, we see if the old location for
		   configuration files exists.  If so, we move it. */
		olddir = g_build_filename (g_get_home_dir (), "." PACKAGE, NULL);
		
		if (g_file_test (olddir, G_FILE_TEST_EXISTS))
			g_rename (olddir, dir);
		else
			g_mkdir (dir, 0700); /* give user all rights */
		
		g_free (olddir);
	}
	
	return dir;
}
Пример #13
0
static void rotate_log (Gstreamill *gstreamill, gchar *log_path, pid_t pid)
{
        GStatBuf st;
        gchar *name;
        glob_t pglob;
        gint i;

        g_stat (log_path, &st);
        if (st.st_size > LOG_SIZE) {
                name = g_strdup_printf ("%s-%lu", log_path, gst_clock_get_time (gstreamill->system_clock));
                g_rename (log_path, name);
                g_free (name);
                GST_INFO ("log rotate %s, process pid %d.", log_path, pid);
                kill (pid, SIGUSR1); /* reopen log file. */
                name = g_strdup_printf ("%s-*", log_path);
                glob (name, 0, NULL, &pglob);
                if (pglob.gl_pathc > LOG_ROTATE) {
                        for (i = 0; i < pglob.gl_pathc - LOG_ROTATE; i++) {
                                g_remove (pglob.gl_pathv[i]);
                        }
                }
                globfree (&pglob);
                g_free (name);
        }
}
Пример #14
0
static gboolean
shell_xdg_migrate_rename (const gchar *old_filename,
                          const gchar *new_filename)
{
	gboolean old_filename_is_dir;
	gboolean old_filename_exists;
	gboolean new_filename_exists;
	gboolean success = TRUE;

	old_filename_is_dir = g_file_test (old_filename, G_FILE_TEST_IS_DIR);
	old_filename_exists = g_file_test (old_filename, G_FILE_TEST_EXISTS);
	new_filename_exists = g_file_test (new_filename, G_FILE_TEST_EXISTS);

	if (!old_filename_exists)
		return TRUE;

	g_print ("  mv %s %s\n", old_filename, new_filename);

	/* It's safe to go ahead and move directories because rename ()
	 * will fail if the new directory already exists with content.
	 * With regular files we have to be careful not to overwrite
	 * new files with old files. */
	if (old_filename_is_dir || !new_filename_exists) {
		if (g_rename (old_filename, new_filename) < 0) {
			g_printerr ("  FAILED: %s\n", g_strerror (errno));
			success = FALSE;
		}
	} else {
		g_printerr ("  FAILED: Destination file already exists\n");
		success = FALSE;
	}

	return success;
}
Пример #15
0
static gboolean
rename_file (const char *old_name,
	     const char *new_name,
	     GError **err)
{
  errno = 0;
  if (g_rename (old_name, new_name) == -1)
    {
      int save_errno = errno;
      gchar *display_old_name = g_filename_display_name (old_name);
      gchar *display_new_name = g_filename_display_name (new_name);

      g_set_error (err,
		   G_FILE_ERROR,
		   g_file_error_from_errno (save_errno),
		   _("Failed to rename file '%s' to '%s': g_rename() failed: %s"),
		   display_old_name,
		   display_new_name,
		   g_strerror (save_errno));

      g_free (display_old_name);
      g_free (display_new_name);
      
      return FALSE;
    }
  
  return TRUE;
}
Пример #16
0
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
  debug ("tgprpl_xfer_recv_on_finished()");
  struct tgp_xfer_send_data *data = _data;
  char *selected = g_strdup (purple_xfer_get_local_filename (data->xfer));

  if (success) {
    debug ("purple_xfer_set_completed");

    // always completed the file transfer to avoid a warning dialogue when closing (Adium)
    purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
    purple_xfer_set_completed (data->xfer, TRUE);

    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_end (data->xfer);
    }
  } else {
    tgp_notify_on_error_gw (TLS, NULL, success);
    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_cancel_remote (data->xfer);
    }
    failure ("recv xfer failed");
  }

  data->loading = FALSE;

  data->xfer->data = NULL;
  purple_xfer_unref (data->xfer);
  tgprpl_xfer_free_data (data);

  debug ("moving transferred file from tgl directory %s to selected target %s", selected, filename);
  g_unlink (selected);
  g_rename (filename, selected);
  g_free (selected);
}
static gboolean
save_file (EBookBackendVCF *vcf)
{
	gboolean retv = FALSE;
	GList *l;
	gchar *new_path;
	gint fd, rv;

	g_warning ("EBookBackendVCF flushing file to disk");

	g_mutex_lock (vcf->priv->mutex);

	new_path = g_strdup_printf ("%s.new", vcf->priv->filename);

	fd = g_open (new_path, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666);
	if (fd == -1) {
		g_warning ("write failed.  could not open output file\n");
		goto out;
	}

	for (l = vcf->priv->contact_list; l; l = l->next) {
		gchar *vcard_str = l->data;
		gint len = strlen (vcard_str);

		rv = write (fd, vcard_str, len);

		if (rv < len) {
			/* XXX */
			g_warning ("write failed.  we need to handle short writes\n");
			g_unlink (new_path);
			goto out;
		}

		rv = write (fd, "\r\n\r\n", 4);
		if (rv < 4) {
			/* XXX */
			g_warning ("write failed.  we need to handle short writes\n");
			g_unlink (new_path);
			goto out;
		}
	}

	if (0 > g_rename (new_path, vcf->priv->filename)) {
		g_warning ("Failed to rename %s: %s\n", vcf->priv->filename, g_strerror(errno));
		g_unlink (new_path);
		goto out;
	}
	retv = TRUE;

out:
	if (fd != -1)
		close (fd);
	g_free (new_path);
	vcf->priv->dirty = !retv;
	g_mutex_unlock (vcf->priv->mutex);

	return retv;
}
Пример #18
0
/**
 * a_try_decompress_file:
 * @name:  The potentially compressed filename
 *
 * Perform magic to decide how which type of decompression to attempt
 */
void a_try_decompress_file (gchar *name)
{
#ifdef HAVE_MAGIC_H
#ifdef MAGIC_VERSION
	// Or magic_version() if available - probably need libmagic 5.18 or so
	//  (can't determine exactly which version the versioning became available)
	g_debug ("%s: magic version: %d", __FUNCTION__, MAGIC_VERSION );
#endif
	magic_t myt = magic_open ( MAGIC_CONTINUE|MAGIC_ERROR|MAGIC_MIME );
	gboolean zip = FALSE;
	gboolean bzip2 = FALSE;
	if ( myt ) {
#ifdef WINDOWS
		// We have to 'package' the magic database ourselves :(
		//  --> %PROGRAM FILES%\Viking\magic.mgc
		int ml = magic_load ( myt, ".\\magic.mgc" );
#else
		// Use system default
		int ml = magic_load ( myt, NULL );
#endif
		if ( ml == 0 ) {
			const char* magic = magic_file (myt, name);
			g_debug ("%s: magic output: %s", __FUNCTION__, magic );

			if ( g_ascii_strncasecmp(magic, "application/zip", 15) == 0 )
				zip = TRUE;

			if ( g_ascii_strncasecmp(magic, "application/x-bzip2", 19) == 0 )
				bzip2 = TRUE;
		}
		else {
			g_critical ("%s: magic load database failure", __FUNCTION__ );
		}

		magic_close ( myt );
	}

	if ( !(zip || bzip2) )
		return;

	if ( zip ) {
		uncompress_zip ( name );
	}
	else if ( bzip2 ) {
		gchar* bz2_name = uncompress_bzip2 ( name );
		if ( bz2_name ) {
			if ( g_remove ( name ) )
				g_critical ("%s: remove file failed [%s]", __FUNCTION__, name );
			if ( g_rename (bz2_name, name) )
				g_critical ("%s: file rename failed [%s] to [%s]", __FUNCTION__, bz2_name, name );
		}
	}

	return;
#endif
}
Пример #19
0
bool M_RenamePath(const char *oldpath, const char *newpath) {
  int res = g_rename(oldpath, newpath);

  if (res == -1) {
    set_file_error_from_errno();
    return false;
  }

  return true;
}
Пример #20
0
static void
do_upgrades_once (NautilusApplication *self)
{
	char *metafile_dir, *updated, *nautilus_dir, *xdg_dir;
	const gchar *message;
	int fd, res;

	if (!self->priv->no_desktop) {
		mark_desktop_files_trusted ();
	}

	metafile_dir = g_build_filename (g_get_home_dir (),
					 ".nautilus/metafiles", NULL);
	if (g_file_test (metafile_dir, G_FILE_TEST_IS_DIR)) {
		updated = g_build_filename (metafile_dir, "migrated-to-gvfs", NULL);
		if (!g_file_test (updated, G_FILE_TEST_EXISTS)) {
			g_spawn_command_line_async (LIBEXECDIR"/nautilus-convert-metadata --quiet", NULL);
			fd = g_creat (updated, 0600);
			if (fd != -1) {
				close (fd);
			}
		}
		g_free (updated);
	}
	g_free (metafile_dir);

	nautilus_dir = g_build_filename (g_get_home_dir (),
					 ".nautilus", NULL);
	xdg_dir = nautilus_get_user_directory ();
	if (g_file_test (nautilus_dir, G_FILE_TEST_IS_DIR)) {
		/* test if we already attempted to migrate first */
		updated = g_build_filename (nautilus_dir, "DEPRECATED-DIRECTORY", NULL);
		message = _("Nautilus 3.0 deprecated this directory and tried migrating "
			    "this configuration to ~/.config/nautilus");
		if (!g_file_test (updated, G_FILE_TEST_EXISTS)) {
			/* rename() works fine if the destination directory is
			 * empty.
			 */
			res = g_rename (nautilus_dir, xdg_dir);

			if (res == -1) {
				fd = g_creat (updated, 0600);
				if (fd != -1) {
					res = write (fd, message, strlen (message));
					close (fd);
				}
			}
		}

		g_free (updated);
	}

	g_free (nautilus_dir);
	g_free (xdg_dir);
}
Пример #21
0
static gboolean
katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies)
{
    gint fn = 0;
    FILE* f = NULL;
    gchar* temporary_filename = NULL;
    GSList* cookies;

    http_cookies->timeout = 0;

    temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL);
    if ((fn = g_mkstemp (temporary_filename)) == -1)
        goto failed;
    if (!((f = fdopen (fn, "wb"))))
        goto failed;

    cookies = soup_cookie_jar_all_cookies (http_cookies->jar);
    for (; cookies != NULL; cookies = g_slist_next (cookies))
    {
        SoupCookie* cookie = cookies->data;
        if (cookie->expires && !soup_date_is_past (cookie->expires))
            write_cookie (f, cookie);
        soup_cookie_free (cookie);
    }
    g_slist_free (cookies);

    if (fclose (f) != 0)
    {
        f = NULL;
        goto failed;
    }
    f = NULL;

    if (g_rename (temporary_filename, http_cookies->filename) == -1)
        goto failed;
    g_free (temporary_filename);

    if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
    {
        g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter);
        http_cookies->counter = 0;
    }
    return FALSE;

failed:
    if (f)
        fclose (f);
    g_unlink (temporary_filename);
    g_free (temporary_filename);
    if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
        g_print ("KatzeHttpCookies: Failed to write '%s'\n",
                 http_cookies->filename);
    return FALSE;
}
Пример #22
0
static void log_init(void)
{
	int fd_log;
	g_unlink(LOGFILE ".old");
	g_rename(LOGFILE, LOGFILE ".old");
	fd_log = open(LOGFILE, O_CREAT|O_APPEND|O_TRUNC|O_WRONLY|O_EXCL, 0640);
	if(fd_log == -1) return;
	dup2(fd_log, 1);
	dup2(fd_log, 2);
	close(fd_log);
}
Пример #23
0
static gint mh_rename_folder(Folder *folder, FolderItem *item,
			     const gchar *name)
{
 	gchar *real_name;
	gchar *oldpath;
	gchar *dirname;
	gchar *newpath, *utf8newpath;
	gchar *paths[2];

	cm_return_val_if_fail(folder != NULL, -1);
	cm_return_val_if_fail(item != NULL, -1);
	cm_return_val_if_fail(item->path != NULL, -1);
	cm_return_val_if_fail(name != NULL, -1);

	oldpath = folder_item_get_path(item);
	if (!is_dir_exist(oldpath))
		make_dir_hier(oldpath);

	dirname = g_path_get_dirname(oldpath);
	real_name = mh_filename_from_utf8(name);
	newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
	g_free(real_name);

	if (g_rename(oldpath, newpath) < 0) {
		FILE_OP_ERROR(oldpath, "rename");
		g_free(oldpath);
		g_free(newpath);
		return -1;
	}

	g_free(oldpath);
	g_free(newpath);

	if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
		dirname = g_path_get_dirname(item->path);
		utf8newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S,
					  name, NULL);
		g_free(dirname);
	} else
		utf8newpath = g_strdup(name);

	g_free(item->name);
	item->name = g_strdup(name);

	paths[0] = g_strdup(item->path);
	paths[1] = utf8newpath;
	g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
			mh_rename_folder_func, paths);

	g_free(paths[0]);
	g_free(paths[1]);
	return 0;
}
Пример #24
0
/* Rename a file. 
 */
int
vips_rename( const char *old_name, const char *new_name )
{
	if( g_rename( old_name, new_name ) ) { 
		vips_error( "rename", 
			_( "unable to rename file \"%s\" as \"%s\", %s" ), 
			old_name, new_name, strerror( errno ) );
                return( -1 );
	}

        return( 0 );
}
Пример #25
0
static void
move_local_favourites_cb(GtkInfoBar* bar,
                         gint res,
                         gpointer udata)
{
    GtFavouritesManager* self = GT_FAVOURITES_MANAGER(udata);
    gchar* fp = FAV_CHANNELS_FILE;
    gchar* new_fp = g_strconcat(fp, ".bak", NULL);

    if (res == GTK_RESPONSE_YES)
    {
        JsonParser* parse = json_parser_new();
        JsonNode* root;
        JsonArray* jarr;
        gchar* fp = FAV_CHANNELS_FILE;
        GError* err = NULL;

        gt_channel_free_list(self->favourite_channels);
        self->favourite_channels = NULL;
        g_signal_emit(self, sigs[SIG_FINISHED_LOADING_FAVOURITES], 0); //TODO: Add a LOADING_FAVOURITES signal

        json_parser_load_from_file(parse, fp, &err);

        if (err)
        {
            g_warning("{GtFavouritesManager} Error move local favourite channels to twitch '%s'", err->message);
            return;
        }

        root = json_parser_get_root(parse);
        jarr = json_node_get_array(root);

        for (GList* l = json_array_get_elements(jarr); l != NULL; l = l->next)
        {
            GtChannel* chan = GT_CHANNEL(json_gobject_deserialize(GT_TYPE_CHANNEL, l->data));
            //TODO: Error handling
            gt_twitch_follow_channel_async(main_app->twitch, gt_channel_get_name(chan), NULL, NULL);
            g_object_unref(chan);
        }

        g_object_unref(parse);
        g_free(fp);

        gt_favourites_manager_load_from_twitch(self);
    }

    g_rename(fp, new_fp);

    g_free(fp);
    g_free(new_fp);
}
Пример #26
0
static s4_t *
xmms_medialib_database_convert (const gchar *database_name,
                                const gchar *indices[])
{
	const gchar *coll_conf, *conv_conf;
	gchar *cmdline, *new_name, *obsolete_name;
	xmms_config_property_t *cfg;
	gint exit_status;
	s4_t *s4;

	cfg = xmms_config_lookup ("collection.directory");
	coll_conf = xmms_config_property_get_string (cfg);

	cfg = xmms_config_lookup ("sqlite2s4.path");
	conv_conf = xmms_config_property_get_string (cfg);

	new_name = xmms_medialib_database_converted_name (database_name);

	cmdline = g_strjoin (" ", conv_conf, database_name,
	                     new_name, coll_conf, NULL);

	xmms_log_info ("Attempting to migrate database to new format.");

	if (!g_spawn_command_line_sync (cmdline, NULL, NULL, &exit_status, NULL) || exit_status) {
		xmms_log_fatal ("Could not run \"%s\", try to run it manually", cmdline);
	}

	g_free (cmdline);

	s4 = s4_open (new_name, indices, 0);
	/* Now we give up */
	if (s4 == NULL) {
		xmms_log_fatal ("Could not open the S4 database");
	}

	xmms_log_info ("Migration successful.");

	/* Move the sqlite database */
	obsolete_name = g_strconcat (database_name, ".obsolete", NULL);
	g_rename (database_name, obsolete_name);
	g_free (obsolete_name);

	/* Update the config path */
	cfg = xmms_config_lookup ("medialib.path");
	xmms_config_property_set_data (cfg, new_name);

	g_free (new_name);

	return s4;
}
Пример #27
0
int
ServiceFileRenameFile(const gchar *srcName,
                      const gchar *dstName)
{
   int ret;

   ret = g_rename(srcName, dstName);
   if (ret < 0) {
      Warning("%s: g_rename(%s, %s) failed (%d)\n", __FUNCTION__, srcName,
              dstName, errno);
   }

   return ret;
}
Пример #28
0
static void
roll_over(Log4gAppender *base)
{
	struct Private *priv = GET_PRIVATE(base);
	Log4gQuietWriter *writer = log4g_writer_appender_get_quiet_writer(base);
	if (writer) {
		gulong size = log4g_counting_quiet_writer_get_count(writer);
		priv->next = size + priv->max;
	}
	if (priv->max > 0) {
		GString *source = g_string_sized_new(128);
		if (G_UNLIKELY(!source)) {
			return;
		}
		GString *target = g_string_sized_new(128);
		if (G_UNLIKELY(!target)) {
			g_string_free(source, TRUE);
			return;
		}
		const gchar *file = log4g_file_appender_get_file(base);
		for (guint i = priv->backup - 1; i >= 1; --i) {
			g_string_printf(source, "%s.%u", file, i);
			g_string_printf(target, "%s.%u", file, i + 1);
			g_rename(source->str, target->str);
		}
		g_string_free(source, TRUE);
		g_string_printf(target, "%s.%u", file, 1);
		if (!g_rename(file, target->str)) {
			g_string_printf(target, "%s", file);
			log4g_file_appender_set_file_full(base, target->str, TRUE,
					log4g_file_appender_get_buffered_io(base),
					log4g_file_appender_get_buffer_size(base));
		}
		g_string_free(target, TRUE);
	}
	priv->next = 0;
}
Пример #29
0
void refreshStatsOfNode(gpointer p)
{
  HostNode *n = (HostNode *)p;
  if(n->fpstat ) {
    fclose(n->fpstat);
    n->fpstat = NULL;

    g_rename(n->statstmpf, n->statsfile);
  }
 
  /* getUpdatesFromStat(n);*/
  unsetLockForHost(n);

  //  rebuilddl = TRUE; /* Trigger a DrawList rebuild */
}
Пример #30
0
/* see http://code.google.com/p/chmsee/issues/detail?id=12 */
void extract_post_file_write(const gchar* fname) {
  gchar* basename = g_path_get_basename(fname);
  gchar* pos = strchr(basename, ';');
  if(pos) {
    gchar* dirname = g_path_get_dirname(fname);
    *pos = '\0';
    gchar* newfname = g_build_filename(dirname, basename, NULL);
    if(g_rename(fname, newfname) != 0) {
      g_error("rename \"%s\" to \"%s\" failed: %s", fname, newfname, strerror(errno));
    }
    g_free(dirname);
    g_free(newfname);
  }
  g_free(basename);
}