This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit 265c39a8935a61b40c085e1411aa8531d1ed167d
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Sat Apr 12 00:22:30 2025 +0100

    implement trashing ... and it'd the default delete
---
 src/backends/default/meson.build |  13 +++
 src/backends/default/open.c      |   2 +-
 src/backends/default/trash.c     | 173 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+), 1 deletion(-)

diff --git a/src/backends/default/meson.build b/src/backends/default/meson.build
index 2d3db91..af4797a 100644
--- a/src/backends/default/meson.build
+++ b/src/backends/default/meson.build
@@ -89,3 +89,16 @@ executable('rm', [
   dependencies: deps,
   install: true,
   install_dir: dir)
+executable('trash', [
+    '../../shared/sha.c',
+    '../../shared/esc.c',
+    '../../shared/util.c',
+    'fs.c',
+    'trash.c',
+    'meta.c',
+    'status.c'
+  ],
+  include_directories: inc,
+  dependencies: deps,
+  install: true,
+  install_dir: dir)
diff --git a/src/backends/default/open.c b/src/backends/default/open.c
index 72e4531..118d9b8 100644
--- a/src/backends/default/open.c
+++ b/src/backends/default/open.c
@@ -1549,7 +1549,7 @@ do_handle_cmd(Cmd *c)
       if (files)
         {
           // XXX: implement trash, but for now use rm
-          _op_run("rm", files, NULL);
+          _op_run("trash", files, NULL);
           EINA_LIST_FREE(files, s) eina_stringshare_del(s);
         }
     }
diff --git a/src/backends/default/trash.c b/src/backends/default/trash.c
new file mode 100644
index 0000000..b8dab77
--- /dev/null
+++ b/src/backends/default/trash.c
@@ -0,0 +1,173 @@
+#include <Eina.h>
+#include <Ecore.h>
+#include <Ecore_File.h>
+#include <Efreet.h>
+#include <Efreet_Mime.h>
+#include <Eet.h>
+
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "meta.h"
+#include "status.h"
+#include "fs.h"
+#include "esc.h"
+#include "sha.h"
+
+static const char *config_dir = NULL;
+
+typedef struct _File_Set
+{
+  const char *src;
+} File_Set;
+
+static void
+mem_abort(void)
+{
+  fprintf(stderr, "Out of memory!\n");
+  abort();
+}
+
+static Eina_List *
+file_set_add(Eina_List *files, const char *src)
+{
+  File_Set *fs = calloc(1, sizeof(File_Set));
+  if (!fs) mem_abort();
+  fs->src = ""
+  if (!fs->src) mem_abort();
+  files = eina_list_append(files, fs);
+  return files;
+}
+
+int
+main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
+{ // rm [src]
+  const char  *fname, *home_dir;
+  Eina_Strbuf *buf   = NULL;
+  Eina_List   *files = NULL, *l;
+  File_Set    *fs;
+  size_t       sz;
+  char        *src = ""
+  char         sbuf[PATH_MAX + 256];
+  Eina_Bool    src_can_write;
+
+  eina_init();
+  eet_init();
+  ecore_init();
+  efreet_init();
+
+  for (;;)
+    { // read stdin of key=val\n ... or end\n
+      if (!fgets(sbuf, sizeof(sbuf), stdin)) break;
+      sz = strlen(sbuf);
+      if (sz < 1) break;                             // too small
+      if (sbuf[sz - 1] == '\n') sbuf[sz - 1] = '\0'; // remove \n if there
+      if (!strncmp(sbuf, "src="" 4))
+        {
+          if (src) free(src);
+          src = "" + 4);
+          if (src) files = file_set_add(files, src);
+          if (src) free(src);
+          src = ""
+        }
+      else if (!strcmp(sbuf, "end")) break;
+    }
+  if (src) free(src);
+  src = ""
+
+  config_dir = getenv("E_HOME_DIR");
+  home_dir   = getenv("HOME");
+  if (!home_dir) return 77; // no $HOME? definitely an error!
+  if (!config_dir)
+    {
+      snprintf(sbuf, sizeof(sbuf), "%s/.e/e", home_dir);
+      config_dir = eina_stringshare_add(sbuf);
+    }
+  meta_init(config_dir);
+
+  buf = eina_strbuf_new();
+  if (!buf) goto err;
+
+  // set up status files for the op
+  status_begin();
+  status_op("trash");
+
+  // build up a list of all files to cp and scan them to find how much
+  EINA_LIST_FOREACH(files, l, fs)
+  {
+    struct stat stsrc;
+
+    if (strlen(fs->src) < 1) goto err2;
+    if (lstat(fs->src, &stsrc) != 0) break;
+    else status_count(1, ecore_file_file_get(fs->src));
+  }
+
+  EINA_LIST_FOREACH(files, l, fs)
+  {
+    Efreet_Uri uri;
+    fname = ecore_file_file_get(fs->src);
+    if (!fname) break;
+
+    // free up previous loop stuff
+    free(src);
+    src = ""
+
+    // src and src temp dir
+    src = ""
+    if (!src) mem_abort();
+
+    // can we modify the meta files in the src? (like cp/rm them?)
+    src_can_write = meta_path_can_write(src);
+
+    // trash the src file and any just rm any meta files
+    uri.protocol = "file";
+    uri.hostname = NULL;
+    uri.path     = src;
+    if (efreet_trash_delete_uri(&uri, EINA_FALSE) == 1)
+      { // it worked so deal with meta/thumbs
+        char *src_meta;
+
+        status_pos(1, ecore_file_file_get(src));
+        // thumbnail file for the base target file
+        if (src_can_write) src_meta = meta_path_find(src, "thumb.efm");
+        else src_meta = meta_path_user_find(src, "thumb.efm");
+        if (src_meta)
+          {
+            fs_cp_rm(src_meta, NULL, EINA_FALSE, EINA_FALSE, EINA_TRUE);
+          }
+        free(src_meta);
+
+        // meta file for the base target file
+        if (src_can_write) src_meta = meta_path_find(src, "meta.efm");
+        else src_meta = meta_path_user_find(src, "meta.efm");
+        if (src_meta)
+          {
+            fs_cp_rm(src_meta, NULL, EINA_FALSE, EINA_FALSE, EINA_TRUE);
+          }
+        free(src_meta);
+      }
+  }
+err2:
+  status_end();
+  // free up leftover strings from loop
+  free(src);
+
+err:
+  if (buf) eina_strbuf_free(buf);
+  EINA_LIST_FREE(files, fs)
+  {
+    eina_stringshare_del(fs->src);
+    free(fs);
+  }
+
+  meta_shutdown();
+
+  efreet_shutdown();
+  ecore_shutdown();
+  eet_shutdown();
+  eina_shutdown();
+  return 0;
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to