Skip to main content

Featured

Build docker image from multiple build contexts

Build docker image from multiple build contexts Building a docker image requires specifying a source of truth to include in the image from a local directory or a remote git repository. In the previous version, the docker BuildKit allows users to specify the build context from a single source of truth only. However, the engineers may need to have the context from different locations based on the type of files. For instance, icons, images or other resources that are not included in the same package, including the resource from other docker images. Fortunately, the Docker Buildx toolkit supports multiple build context flag for Docker 1.4. Let's learn how to use this new feature. The following list is a shortcut for jumping into a specific topic handy. What version of Docker is this tutorial targeting? How to specify the version of Dockerfile frontend? Ho

[WinAPI]GetFileAttributes在Vista 64的%AppData%下無法正確判定是否為資料夾

一般在判定取得的路徑為檔案路徑或是資料夾路徑時,可透過GetFileAttributes來得知路徑的屬性。

這個方法在XP的版本下的時候,都可以正常取得到FILE_ATTRIBUTE_DIRECTORY,所以也可以正常的判定是否為資料夾。

然而在Vista上任意的路徑(如桌面、All User等)內的資料夾或是檔案路徑也都可以正常判定。

但是當路徑內轉指向%AppData%(c:\Users\CurUsrName\AppData\Roaming)的時候,如也是透過GetFileAttributes來取得路徑屬性的話,資料夾部分則會得到8208、檔案則會得到8224兩組值。

這兩組值並沒有在MSDN內被提供(http://msdn.microsoft.com/en-us/library/aa364944(VS.85).aspx

所以後來經過Jacob的提醒,去檢查了這兩組值的binary值。
發現
8208 = 10 0000 0001 0000
8248 = 10 0000 0010 0000

這與
FILE_ATTRIBUTE_DIRECTORY = 00 0000 0001 0000
FILE_ATTRIBUTE_ARCHIVE = 00 0000 0010 0000

差了一個最高位的屬性。

所以這邊就根據Jacob的建議,在屬性判斷時,多做了BitMask來過濾掉其他不相干的屬性。

所以目前處理方式如下

```cpp
switch ( GetFileAttributes(szPath) & FILE_ATTRIBUTE_DIRECTORY )
{
case FILE_ATTRIBUTE_DIRECTORY:
  return IS_DIR;
case FILE_ATTRIBUTE_ARCHIVE:
  return IS_FILE;
case INVALID_FILE_ATTRIBUTES:
  return IS_INVALID;
default:
  return IS_UNKNOWN;
}
```

至於最高位的那個bit是啥用途,那就等候M$大帝國公布啦XD

Comments

Popular Posts