Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyIKn-0008Ky-GT for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 15:38:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyIKm-0001GS-5U for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 15:38:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyIKk-0001G5-Uq for pgsql-hackers@lists.postgresql.org; Mon, 25 Feb 2019 15:38:23 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyIKh-0000Q6-CM for pgsql-hackers@postgresql.org; Mon, 25 Feb 2019 15:38:21 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 8945A21C7C87 for ; Mon, 25 Feb 2019 18:38:16 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.200] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 626D921C7C4D for ; Mon, 25 Feb 2019 18:38:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1551109096; bh=beE2o/I/7iTysz/k8tu92unYacwyCrh0ddKj7ljwS9g=; h=To:From:Subject:Date; b=d8XkUB4J2xmHGEQgR59ErRIKKnpoRkuWm0Foeijmx00VwGrJbjenG5j2PTB3eWHEO +9Pfhzq2938fKXwGaKczUG2jWSk+mPRdK/6lSBPsp1cqsxXeXw6gcWh+ZFotM4Vp+f 0jGIre5rYbj5AymLoCJFVxkXTML0p3HCcr3jZvyg= To: PostgreSQL Hackers From: Konstantin Knizhnik Subject: readdir is incorrectly implemented at Windows Message-ID: <2cad7829-8d66-e39c-b937-ac825db5203d@postgrespro.ru> Date: Mon, 25 Feb 2019 18:38:16 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3D0289F58D2F6B2DCB10C6F4" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------3D0289F58D2F6B2DCB10C6F4 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi hackers, Small issue with readir implementation for Windows. Right now it returns ENOENT in case of any error returned by FindFirstFile. So all places in Postgres where opendir/listdir are used will assume that directory is empty and do nothing without reporting any error. It is not so good if directory is actually not empty but there are not enough permissions for accessing the directory and FindFirstFile returns ERROR_ACCESS_DENIED: struct dirent * readdir(DIR *d) {     WIN32_FIND_DATA fd;     if (d->handle == INVALID_HANDLE_VALUE)     {         d->handle = FindFirstFile(d->dirname, &fd);         if (d->handle == INVALID_HANDLE_VALUE)         {             errno = ENOENT;             return NULL;         }     } Attached please find small patch fixing the problem. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------3D0289F58D2F6B2DCB10C6F4 Content-Type: text/x-patch; name="dirent.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dirent.patch" diff --git a/src/port/dirent.c b/src/port/dirent.c index 7a91450..284bf27 100644 --- a/src/port/dirent.c +++ b/src/port/dirent.c @@ -83,7 +83,13 @@ readdir(DIR *d) d->handle = FindFirstFile(d->dirname, &fd); if (d->handle == INVALID_HANDLE_VALUE) { - errno = ENOENT; + if (GetLastError() == ERROR_FILE_NOT_FOUND) + { + /* No more files, force errno=0 (unlike mingw) */ + errno = 0; + return NULL; + } + _dosmaperr(GetLastError()); return NULL; } } --------------3D0289F58D2F6B2DCB10C6F4--