Skip to content

Commit d2bcd9f

Browse files
John Pfuntnerphilpep
John Pfuntner
authored andcommitted
Teaching GNUFile methods to follow symlinks
On Linux systems, if File.mode is used on a file that's a symlink, it will return 0x777 because that's the "mode" of the symlink but mode is pretty meaningless for a symlink. By doing `stat -L ...` the command will automatically resolve symlinks.
1 parent 525bde4 commit d2bcd9f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

testinfra/modules/file.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -223,38 +223,38 @@ def get_module_class(cls, host):
223223
class GNUFile(File):
224224
@property
225225
def user(self):
226-
return self.check_output("stat -c %%U %s", self.path)
226+
return self.check_output("stat -Lc %%U %s", self.path)
227227

228228
@property
229229
def uid(self):
230-
return int(self.check_output("stat -c %%u %s", self.path))
230+
return int(self.check_output("stat -Lc %%u %s", self.path))
231231

232232
@property
233233
def group(self):
234-
return self.check_output("stat -c %%G %s", self.path)
234+
return self.check_output("stat -Lc %%G %s", self.path)
235235

236236
@property
237237
def gid(self):
238-
return int(self.check_output("stat -c %%g %s", self.path))
238+
return int(self.check_output("stat -Lc %%g %s", self.path))
239239

240240
@property
241241
def mode(self):
242242
# Supply a base of 8 when parsing an octal integer
243243
# e.g. int('644', 8) -> 420
244-
return int(self.check_output("stat -c %%a %s", self.path), 8)
244+
return int(self.check_output("stat -Lc %%a %s", self.path), 8)
245245

246246
@property
247247
def mtime(self):
248-
ts = self.check_output("stat -c %%Y %s", self.path)
248+
ts = self.check_output("stat -Lc %%Y %s", self.path)
249249
return datetime.datetime.fromtimestamp(float(ts))
250250

251251
@property
252252
def size(self):
253-
return int(self.check_output("stat -c %%s %s", self.path))
253+
return int(self.check_output("stat -Lc %%s %s", self.path))
254254

255255
@property
256256
def inode(self):
257-
return int(self.check_output("stat -c %%i %s", self.path))
257+
return int(self.check_output("stat -Lc %%i %s", self.path))
258258

259259
@property
260260
def md5sum(self):

0 commit comments

Comments
 (0)