smbd: Add "hide new files" option
authorVolker Lendecke <vl@samba.org>
Thu, 23 Aug 2018 11:51:26 +0000 (13:51 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 8 Nov 2018 23:47:22 +0000 (00:47 +0100)
See the manpage for the description

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
docs-xml/smbdotconf/filename/hidenewfilestimeout.xml [new file with mode: 0644]
source3/smbd/dir.c

diff --git a/docs-xml/smbdotconf/filename/hidenewfilestimeout.xml b/docs-xml/smbdotconf/filename/hidenewfilestimeout.xml
new file mode 100644 (file)
index 0000000..ca93e72
--- /dev/null
@@ -0,0 +1,15 @@
+<samba:parameter name="hide new files timeout"
+                 context="S"
+                 type="integer"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+ <description>
+   <para>Setting this parameter to something but 0 hides files
+   that have been modified less than N seconds ago.</para>
+   <para>It can be used for ingest/process queue style workloads. A
+   processing application should only see files that are definitely
+   finished. As many applications do not have proper external workflow
+   control, this can be a way to make sure processing does not
+   interfere with file ingest.</para>
+</description>
+<value type="default">0</value>
+</samba:parameter>
index c3af5233e9861892a8eea0c04835fd41f5fc1840..f05d7a290e552ebd7e0851020655ff38805c2261 100644 (file)
@@ -1536,6 +1536,7 @@ bool is_visible_file(connection_struct *conn, const char *dir_path,
        bool hide_unreadable = lp_hide_unreadable(SNUM(conn));
        bool hide_unwriteable = lp_hide_unwriteable_files(SNUM(conn));
        bool hide_special = lp_hide_special_files(SNUM(conn));
+       int hide_new_files_timeout = lp_hide_new_files_timeout(SNUM(conn));
        char *entry = NULL;
        struct smb_filename *smb_fname_base = NULL;
        bool ret = false;
@@ -1550,7 +1551,11 @@ bool is_visible_file(connection_struct *conn, const char *dir_path,
                return False;
        }
 
-       if (hide_unreadable || hide_unwriteable || hide_special) {
+       if (hide_unreadable ||
+           hide_unwriteable ||
+           hide_special ||
+           (hide_new_files_timeout != 0))
+       {
                entry = talloc_asprintf(talloc_tos(), "%s/%s", dir_path, name);
                if (!entry) {
                        ret = false;
@@ -1603,6 +1608,17 @@ bool is_visible_file(connection_struct *conn, const char *dir_path,
                        ret = false;
                        goto out;
                }
+
+               if (hide_new_files_timeout != 0) {
+
+                       double age = timespec_elapsed(
+                               &smb_fname_base->st.st_ex_mtime);
+
+                       if (age < (double)hide_new_files_timeout) {
+                               ret = false;
+                               goto out;
+                       }
+               }
        }
 
        ret = true;