]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Slightly simplify smbd_dirptr_get_entry()
authorVolker Lendecke <vl@samba.org>
Wed, 21 Jun 2023 15:48:24 +0000 (17:48 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 30 Jun 2023 10:42:36 +0000 (10:42 +0000)
Implementing virtually empty directories for "dont descend" looks
easier to me this way. It should also be an optimization, because now
we don't walk the whole directory anymore after . and .., which always
come first anyway.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/dir.c

index 8c5943bf88b2add4bb6a01072bf1c59b06029856..6ad2d5c94843d3362980d92c7e7f2b2413aa1f50 100644 (file)
@@ -546,12 +546,19 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                return true;
        }
 
+       if (dont_descend && (dptr_FileNumber(dirptr) >= 2)) {
+               /*
+                * . and .. were returned first, we're done showing
+                * the directory as empty.
+                */
+               return false;
+       }
+
        pathlen = strlen(dpath);
        slashlen = ( dpath[pathlen-1] != '/') ? 1 : 0;
 
        while (true) {
                char *dname = NULL;
-               bool isdots;
                char *fname = NULL;
                char *pathreal = NULL;
                struct smb_filename *atname = NULL;
@@ -574,12 +581,6 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                        return false;
                }
 
-               isdots = (ISDOT(dname) || ISDOTDOT(dname));
-               if (dont_descend && !isdots) {
-                       TALLOC_FREE(dname);
-                       continue;
-               }
-
                if (IS_VETO_PATH(conn, dname)) {
                        TALLOC_FREE(dname);
                        continue;