コード例 #1
0
ファイル: tracker-storage.c プロジェクト: N4rm0/tracker
static void
mount_add (TrackerStorage *storage,
           GMount         *mount)
{
	TrackerStoragePrivate *priv;
	GFile *root;
	GVolume *volume;
	gchar *mount_name, *mount_path, *uuid;
	gboolean is_optical = FALSE;
	gboolean is_removable = FALSE;

	/* Get mount name */
	mount_name = g_mount_get_name (mount);

	/* Get root path of the mount */
	root = g_mount_get_root (mount);
	mount_path = g_file_get_path (root);

	g_debug ("Found '%s' mounted on path '%s'",
	         mount_name,
	         mount_path);

	/* Do not process shadowed mounts! */
	if (g_mount_is_shadowed (mount)) {
		g_debug ("  Skipping shadowed mount '%s'", mount_name);
		g_object_unref (root);
		g_free (mount_path);
		g_free (mount_name);
		return;
	}

	priv = TRACKER_STORAGE_GET_PRIVATE (storage);

	/* fstab partitions may not have corresponding
	 * GVolumes, so volume may be NULL */
	volume = g_mount_get_volume (mount);
	if (volume) {
		/* GMount with GVolume */

		/* Try to get UUID from the Volume.
		 * Note that g_volume_get_uuid() is NOT equivalent */
		uuid = g_volume_get_identifier (volume,
		                                G_VOLUME_IDENTIFIER_KIND_UUID);
		if (!uuid) {
			gchar *content_type;
			gboolean is_multimedia;
			gboolean is_blank;

			/* Optical discs usually won't have UUID in the GVolume */
			content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank);
			is_removable = TRUE;

			/* We don't index content which is video, music or blank */
			if (!is_multimedia && !is_blank) {
				uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5,
				                                      mount_name,
				                                      -1);
				g_debug ("  No UUID, generated:'%s' (based on mount name)", uuid);
				g_debug ("  Assuming GVolume has removable media, if wrong report a bug! "
				         "content type is '%s'",
				         content_type);
			} else {
				g_debug ("  Being ignored because mount with volume is music/video/blank "
				         "(content type:%s, optical:%s, multimedia:%s, blank:%s)",
				         content_type,
				         is_optical ? "yes" : "no",
				         is_multimedia ? "yes" : "no",
				         is_blank ? "yes" : "no");
			}

			g_free (content_type);
		} else {
			/* Any other removable media will have UUID in the
			 * GVolume. Note that this also may include some
			 * partitions in the machine which have GVolumes
			 * associated to the GMounts. We also check a drive
			 * exists to be sure the device is local. */
			GDrive *drive;

			drive = g_volume_get_drive (volume);

			if (drive) {
				/* We can't mount/unmount system volumes, so tag
				 * them as non removable. */
				is_removable = g_volume_can_mount (volume);
				g_debug ("  Found mount with volume and drive which %s be mounted: "
				         "Assuming it's %s removable, if wrong report a bug!",
				         is_removable ? "can" : "cannot",
				         is_removable ? "" : "not");
				g_object_unref (drive);
			} else {
				/* Note: not sure when this can happen... */
				g_debug ("  Mount with volume but no drive, "
				         "assuming not a removable device, "
				         "if wrong report a bug!");
				is_removable = FALSE;
			}
		}

		g_object_unref (volume);
	} else {
		/* GMount without GVolume.
		 * Note: Never found a case where this g_mount_get_uuid() returns
		 * non-NULL... :-) */
		uuid = g_mount_get_uuid (mount);
		if (!uuid) {
			if (mount_path) {
				gchar *content_type;
				gboolean is_multimedia;
				gboolean is_blank;

				content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank);

				/* Note: for GMounts without GVolume, is_blank should NOT be considered,
				 * as it may give unwanted results... */
				if (!is_multimedia) {
					uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5,
					                                      mount_path,
					                                      -1);
					g_debug ("  No UUID, generated:'%s' (based on mount path)", uuid);
				} else {
					g_debug ("  Being ignored because mount is music/video "
					         "(content type:%s, optical:%s, multimedia:%s)",
					         content_type,
					         is_optical ? "yes" : "no",
					         is_multimedia ? "yes" : "no");
				}

				g_free (content_type);
			} else {
				g_debug ("  Being ignored because mount has no GVolume (i.e. not user mountable) "
				         "and has no mount root path available");
			}
		}
	}

	/* If we got something to be used as UUID, then add the mount
	 * to the TrackerStorage */
	if (uuid && mount_path && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) {
		g_debug ("  Adding mount point with UUID: '%s', removable: %s, optical: %s, path: '%s'",
		         uuid,
		         is_removable ? "yes" : "no",
		         is_optical ? "yes" : "no",
		         mount_path);
		mount_add_new (storage, uuid, mount_path, mount_name, is_removable, is_optical);
	} else {
		g_debug ("  Skipping mount point with UUID: '%s', path: '%s', already managed: '%s'",
		         uuid ? uuid : "none",
		         mount_path ? mount_path : "none",
		         (uuid && g_hash_table_lookup (priv->mounts_by_uuid, uuid)) ? "yes" : "no");
	}

	g_free (mount_name);
	g_free (mount_path);
	g_free (uuid);
	g_object_unref (root);
}