Diff of /src/function.c [0b59e9] .. [803699] Maximize Restore

  Switch to side-by-side view

--- a/src/function.c
+++ b/src/function.c
@@ -17,13 +17,13 @@
 #include "common.h"
 #include "smbitem.h"
 #include "samba.h"
-#include "stat_workaround.h"
 #include "function.h"
 
 size_t		function_free_space_size	= 0;
 int		function_quiet_flag		= 1;
 int		function_show_dollar_shares	= 0;
 int		function_show_hidden_hosts	= 0;
+int		function_kde_workaround_depth	= 3;
 
 pthread_mutex_t	m_function		= PTHREAD_MUTEX_INITIALIZER;
 
@@ -99,9 +99,42 @@
     return flag;
 }
 
-inline int function_check_xattr_name(const char *name){
-    static char	*xattr_name = "system.nt_sec_desc.";
-    return (strncmp(name, xattr_name, strlen(xattr_name)) == 0);
+int function_set_kde_workaround_depth(int depth){
+    if (depth < -1) return 0;
+    DPRINTF(7, "depth=%d\n", depth);
+    pthread_mutex_lock(&m_function);
+    function_kde_workaround_depth = depth;
+    pthread_mutex_unlock(&m_function);
+    return 1;
+}
+
+int function_get_kde_workaround_depth(void){
+    int depth;
+
+    pthread_mutex_lock(&m_function);
+    depth = function_kde_workaround_depth;
+    pthread_mutex_unlock(&m_function);
+    DPRINTF(7, "depth=%d\n", depth);
+    return depth;
+}
+
+int function_is_kde_workaround(const char *path){
+    const char		*kde_dir_name = ".directory";
+    const ssize_t	kde_dir_len = strlen(kde_dir_name);
+    int			i, depth = function_get_kde_workaround_depth();
+    const char		*path_end;
+
+    for(i = 0; (i < depth) || (depth == -1); i++){
+	while(*path == '/') path++;
+	if (*path == '\0') break;
+
+	path_end = path;
+	while((*path_end != '/') && (*path_end != '\0')) path_end++;
+	if ((path_end - path == kde_dir_len) &&
+	    (strncmp(path, kde_dir_name, kde_dir_len) == 0)) return 1;
+	path = path_end;
+    }
+    return 0;
 }
 
 inline samba_fd function_get_fd(struct fuse_file_info *fi){
@@ -380,7 +413,7 @@
     char		buf[2048];
 
     DPRINTF(5, "(%s)\n", path);
-    if (stat_workaround_is_name_ignored(path)) return -ENOENT;
+    if (function_is_kde_workaround(path)) return -ENOENT;
     switch(smbitem_what_is(path)){
 	case SMBITEM_SMBNETFS_DIR:
 	    while(*path == '/') path++;
@@ -521,8 +554,7 @@
 			    const char *value, size_t size, int flags){
     DPRINTF(5, "(%s, name=%s, value=%s, size=%d, flags=%o)\n", path,
 	name, value, (int) size, flags);
-    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -ENOTSUP;
-    if (!function_check_xattr_name(name)) return -ENOTSUP;
+    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -EINVAL;
     if (samba_setxattr(path, name, value, size, flags) != 0) return -errno;
     return 0;
 }
@@ -531,8 +563,7 @@
 static int function_getxattr(const char *path, const char *name,
 			    char *value, size_t size){
     DPRINTF(5, "(%s, name=%s, size=%d)\n", path, name, (int) size);
-    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -ENOTSUP;
-    if (!function_check_xattr_name(name)) return -ENOTSUP;
+    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -EINVAL;
     if (samba_getxattr(path, name, value, size) != 0) return -errno;
     return 0;
 }
@@ -540,7 +571,7 @@
 /* libfuse does not support llistxattr() and flistxattr(), but samba does */
 static int function_listxattr(const char *path, char *list, size_t size){
     DPRINTF(5, "(%s, size=%d)\n", path, (int) size);
-    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -ENOTSUP;
+    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -EINVAL;
     if (samba_listxattr(path, list, size) != 0) return -errno;
     return 0;
 }
@@ -548,8 +579,7 @@
 /* libfuse does not support lremovexattr() and fremovexattr(), but samba does */
 static int function_removexattr(const char *path, const char *name){
     DPRINTF(5, "(%s, name=%s)\n", path, name);
-    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -ENOTSUP;
-    if (!function_check_xattr_name(name)) return -ENOTSUP;
+    if (smbitem_what_is(path) != SMBITEM_SMB_SHARE_ITEM) return -EINVAL;
     if (samba_removexattr(path, name) != 0) return -errno;
     return 0;
 }