Skip to content

Commit 999c824

Browse files
committed
LI #5: Several Path:: methods fail on a broken symlink
- Added a protective existence check.
1 parent c3d7db1 commit 999c824

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ install_manifest.txt
66
libshared.a
77
cmake.h
88
lex
9+
patches

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ master/HEAD
88
(thanks to Paul J. Fenwick)
99
- Datetime::timeRelative now controls whether "0:00:01" means today or is
1010
projected to tomorrow if before the current time.
11+
- LI #5 Several Path:: methods fail on a broken symlink
1112

1213
tasksh-1.2.0 (2017-05-10)
1314

src/FS.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ bool Path::is_absolute () const
183183
////////////////////////////////////////////////////////////////////////////////
184184
bool Path::is_link () const
185185
{
186+
if (! exists ())
187+
return false;
188+
186189
struct stat s {};
187190
if (lstat (_data.c_str (), &s))
188191
throw format ("lstat error {1}: {2}", errno, strerror (errno));
@@ -195,6 +198,9 @@ bool Path::is_link () const
195198
// to determine.
196199
bool Path::readable () const
197200
{
201+
if (! exists ())
202+
return false;
203+
198204
auto status = access (_data.c_str (), R_OK);
199205
if (status == -1 && errno != EACCES)
200206
throw format ("access error {1}: {2}", errno, strerror (errno));
@@ -207,6 +213,9 @@ bool Path::readable () const
207213
// to determine.
208214
bool Path::writable () const
209215
{
216+
if (! exists ())
217+
return false;
218+
210219
auto status = access (_data.c_str (), W_OK);
211220
if (status == -1 && errno != EACCES)
212221
throw format ("access error {1}: {2}", errno, strerror (errno));
@@ -219,6 +228,9 @@ bool Path::writable () const
219228
// to determine.
220229
bool Path::executable () const
221230
{
231+
if (! exists ())
232+
return false;
233+
222234
auto status = access (_data.c_str (), X_OK);
223235
if (status == -1 && errno != EACCES)
224236
throw format ("access error {1}: {2}", errno, strerror (errno));

0 commit comments

Comments
 (0)