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 c9f0b85cdce8eb36567c30ba51ab2c78661e40a7
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Thu Jun 13 10:45:32 2024 +0100
move mirror parent mode to util shared src
---
src/backends/default/meson.build | 5 ++++-
src/backends/default/meta.c | 15 ++-------------
src/backends/default/thumb.c | 17 +++--------------
src/shared/util.c | 27 +++++++++++++++++++++++++++
src/shared/util.h | 8 ++++++++
5 files changed, 44 insertions(+), 28 deletions(-)
diff --git a/src/backends/default/meson.build b/src/backends/default/meson.build
index b2f1749..5034a0f 100644
--- a/src/backends/default/meson.build
+++ b/src/backends/default/meson.build
@@ -10,9 +10,10 @@ executable('open', [
'../../shared/cmd.c',
'../../shared/sha.c',
'../../shared/esc.c',
+ '../../shared/util.c',
'../../backends/common/fs_backend_core.c',
'open.c',
- 'meta.c'
+ 'meta.c',
],
include_directories: inc,
dependencies: deps,
@@ -20,6 +21,7 @@ executable('open', [
install_dir: dir)
executable('thumb', [
'../../shared/sha.c',
+ '../../shared/util.c',
'thumb.c',
'thumb_util_img.c',
'thumb_util_search.c',
@@ -38,6 +40,7 @@ executable('thumb', [
executable('mv', [
'../../shared/sha.c',
'../../shared/esc.c',
+ '../../shared/util.c',
'fs.c',
'mv.c',
'meta.c',
diff --git a/src/backends/default/meta.c b/src/backends/default/meta.c
index 83384ca..c366f3b 100644
--- a/src/backends/default/meta.c
+++ b/src/backends/default/meta.c
@@ -7,6 +7,7 @@
#include <sys/stat.h>
#include "sha.h"
#include "meta.h"
+#include "util.h"
// This is a metadata store to store added metadata for any given file path.
// For example store the x,y location of a file, added comments, flags a user
@@ -381,9 +382,7 @@ meta_path_user_find(const char *path, const char *extn)
Eina_Bool
meta_path_prepare(const char *path)
{ // "path" is the path returned by meta_path_user_find() or meta_path_find()
- struct stat st;
Eina_Bool ret = EINA_FALSE;
- char *dir_parent;
char *dir = ecore_file_dir_get(path);
if (!dir) return ret;
@@ -393,17 +392,7 @@ meta_path_prepare(const char *path)
if (ecore_file_mkdir(dir)) ret = EINA_TRUE;
else if (ecore_file_mkpath(dir)) ret = EINA_TRUE;
}
- dir_parent = ecore_file_dir_get(dir);
- if (dir_parent)
- {
- // copy the parent dir mode to the child .efm
- if (lstat(dir_parent, &st) == 0)
- {
- chown(dir, st.st_uid, st.st_gid);
- chmod(dir, st.st_mode);
- }
- free(dir_parent);
- }
+ util_file_mode_parent_copy(dir, EINA_TRUE);
free(dir);
return ret;
}
diff --git a/src/backends/default/thumb.c b/src/backends/default/thumb.c
index e0aa90b..ded62e5 100644
--- a/src/backends/default/thumb.c
+++ b/src/backends/default/thumb.c
@@ -1,4 +1,5 @@
#include "thumb.h"
+#include "util.h"
Evas_Object *win = NULL;
Evas_Object *subwin = NULL;
@@ -25,24 +26,12 @@ _thumb_output_open(const char *thumb)
static void
_thumb_output_close(Eet_File *ef, const char *thumb)
{ // close thumnb file and atomically rename tmp file on top of target
- char buf[PATH_MAX], *dir;
- struct stat st;
+ char buf[PATH_MAX];
eet_close(ef);
snprintf(buf, sizeof(buf), "%s.tmp", thumb);
// fix permissions on file to match parent dir
- dir = ecore_file_dir_get(buf);
- if (dir)
- {
- if (lstat(dir, &st) == 0)
- {
- chown(buf, st.st_uid, st.st_gid);
- chmod(buf, st.st_mode
- & (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
- | S_IWOTH));
- }
- free(dir);
- }
+ util_file_mode_parent_copy(buf, EINA_FALSE);
ecore_file_mv(buf, thumb);
}
diff --git a/src/shared/util.c b/src/shared/util.c
new file mode 100644
index 0000000..0f79715
--- /dev/null
+++ b/src/shared/util.c
@@ -0,0 +1,27 @@
+#include "util.h"
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+void
+util_file_mode_parent_copy(const char *file, Eina_Bool is_dir)
+{
+ struct stat st;
+ char *s, *dir_parent = strdup(file);
+
+ if (!dir_parent) return;
+ s = strrchr(file, '/');
+ if (!s) goto err;
+ s[1] = '\0'; // get parent dir by truncating after /
+ if (lstat(dir_parent, &st) == 0)
+ { // copy the parent dir mode to the child file given
+ chown(file, st.st_uid, st.st_gid);
+ // if it's not a dir - filter out execute mode
+ if (!is_dir)
+ st.st_mode &= S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+ chmod(file, st.st_mode);
+ }
+err:
+ free(dir_parent);
+}
\ No newline at end of file
diff --git a/src/shared/util.h b/src/shared/util.h
new file mode 100644
index 0000000..4a7abdf
--- /dev/null
+++ b/src/shared/util.h
@@ -0,0 +1,8 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <Eina.h>
+
+void util_file_mode_parent_copy(const char *file, Eina_Bool is_dir);
+
+#endif
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.