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 1gyzlb-0001j2-VT for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 14:01:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyzla-0004gq-HD for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 14:00:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyzla-0004gi-6b for pgsql-hackers@lists.postgresql.org; Wed, 27 Feb 2019 14:00:58 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyzlX-0001p9-7u for pgsql-hackers@lists.postgresql.org; Wed, 27 Feb 2019 14:00:57 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id C7ED621CC9E9 for ; Wed, 27 Feb 2019 17:00:53 +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.31] (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 77EB221CC9C8 for ; Wed, 27 Feb 2019 17:00:53 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1551276053; bh=0nK8/C9CF+hkItH6NtYvAvfpQOFbUCPBFtHkyyW346k=; h=Subject:To:References:From:Date:In-Reply-To; b=QlC0Yq8OxWOwT5WS9937emmlRoek5O4c6ENDi5wpbaAxegA/BLl/x4V5/hfTffBDy uIct+j4WiddK0G1C6LpLY4e0bqrNnBnSpGySEVqjgyZ+yxRNaKwpktIyojBLMfbudK 0H/QOJYj6o0fqyPm0uMdLlD+v2xPmbZLdym4gSeY= Subject: Re: readdir is incorrectly implemented at Windows To: pgsql-hackers@lists.postgresql.org References: <2cad7829-8d66-e39c-b937-ac825db5203d@postgrespro.ru> From: Grigory Smolkin Message-ID: <591b93df-3d05-c88e-54bd-29c6a94d2a2d@postgrespro.ru> Date: Wed, 27 Feb 2019 17:00:52 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <2cad7829-8d66-e39c-b937-ac825db5203d@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Originally bug was reported by Yuri Kurenkov: https://github.com/postgrespro/pg_probackup/issues/48 As pg_probackup rely on readdir() for listing files to backup, wrong permissions could lead to a broken backup. On 02/25/2019 06:38 PM, Konstantin Knizhnik wrote: > 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. > -- Grigory Smolkin Postgres Professional: http://www.postgrespro.com The Russian Postgres Company