[gnome-builder] io: add private API to check if file exists on host



commit 3925adcf70b73bc389ba87b33e308b5a5c95ad75
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 9 15:45:57 2021 -0700

    io: add private API to check if file exists on host

 src/libide/io/ide-gfile-private.h |  4 +++-
 src/libide/io/ide-gfile.c         | 27 +++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/io/ide-gfile-private.h b/src/libide/io/ide-gfile-private.h
index b066a0475..7bb9799c4 100644
--- a/src/libide/io/ide-gfile-private.h
+++ b/src/libide/io/ide-gfile-private.h
@@ -24,6 +24,8 @@
 
 G_BEGIN_DECLS
 
-GFile *_ide_g_file_readlink (GFile *file);
+GFile    *_ide_g_file_readlink             (GFile        *file);
+gboolean  _ide_g_file_query_exists_on_host (GFile        *file,
+                                            GCancellable *cancellable);
 
 G_END_DECLS
diff --git a/src/libide/io/ide-gfile.c b/src/libide/io/ide-gfile.c
index 51b761f51..8f0ccbd83 100644
--- a/src/libide/io/ide-gfile.c
+++ b/src/libide/io/ide-gfile.c
@@ -1032,3 +1032,30 @@ ide_g_file_find_in_ancestors_finish (GAsyncResult  *result,
 
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
+
+gboolean
+_ide_g_file_query_exists_on_host (GFile        *file,
+                                  GCancellable *cancellable)
+{
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeSubprocess) subprocess = NULL;
+
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
+
+  if (!g_file_is_native (file))
+    return FALSE;
+
+  if (!ide_is_flatpak ())
+    return g_file_query_exists (file, cancellable);
+
+  launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE | 
G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+  ide_subprocess_launcher_push_argv (launcher, "ls");
+  ide_subprocess_launcher_push_argv (launcher, "-d");
+  ide_subprocess_launcher_push_argv (launcher, g_file_peek_path (file));
+
+  if (!(subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, NULL)))
+    return FALSE;
+
+  return ide_subprocess_wait_check (subprocess, cancellable, NULL);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]