cloudfoundry-attic / warden

Cloud Foundry - the open platform as a service project
Apache License 2.0
283 stars 108 forks source link

A Question About wshd c code #83

Closed ChampionL closed 9 years ago

ChampionL commented 9 years ago

warden/warden/src/wsh/wshd.c line 143 void assert_directory(const char *path) is it below code unnessary? if (!S_ISDIR(st.st_mode)) { fprintf(stderr, "stat(\"%s\"): %s\n", path, "No such directory"); exit(1); } because stat function already check the condition that directory does not exist。why we need to check it again,does this code will never execute?

cf-gitbot commented 9 years ago

We have created an issue in Pivotal Tracker to manage this. You can view the current status of your issue at: https://www.pivotaltracker.com/story/show/84831044.

julz commented 9 years ago

The first check asserts that it exists. The second asserts that it is a directory (as opposed to e.g. a file). if a file exists at the passed path rather than a directory the first stat will succeed but the S_ISDIR check will fail. This is why the second check is needed.

ChampionL commented 9 years ago

@julz Thank You

glyn commented 9 years ago

The first check is for the existence of a directory or a file, so the other check is needed to ensure it really is a directory and not a file.