Skip to content

Commit 080eba5

Browse files
committed
only optimize for SystemPath
also add some additional optimizations
1 parent 4cc2852 commit 080eba5

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/path.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ julia> mode(p"src/FilePathsBase.jl")
512512
-rw-r--r--
513513
```
514514
"""
515-
mode(fp::AbstractPath) = Mode(stat(string(fp)).mode)
516-
Base.filesize(fp::AbstractPath) = stat(string(fp)).size
515+
mode(fp::AbstractPath) = stat(fp).mode
516+
Base.filesize(fp::AbstractPath) = stat(fp).size
517517

518518
"""
519519
modified(fp::AbstractPath) -> DateTime
@@ -526,7 +526,7 @@ julia> modified(p"src/FilePathsBase.jl")
526526
2017-06-20T04:01:09
527527
```
528528
"""
529-
modified(fp::AbstractPath) = unix2datetime(stat(string(fp)).mtime)
529+
modified(fp::AbstractPath) = stat(fp).mtime
530530

531531
"""
532532
created(fp::AbstractPath) -> DateTime
@@ -542,7 +542,7 @@ julia> created(p"src/FilePathsBase.jl")
542542
created(fp::AbstractPath) = stat(fp).ctime
543543
Base.isdir(fp::AbstractPath) = isdir(mode(fp))
544544
Base.isfile(fp::AbstractPath) = isfile(mode(fp))
545-
Base.islink(fp::AbstractPath) = islink(mode(fp))
545+
Base.islink(fp::AbstractPath) = islink(lstat(fp).mode)
546546
Base.issocket(fp::AbstractPath) = issocket(mode(fp))
547547
Base.isfifo(fp::AbstractPath) = issocket(mode(fp))
548548
Base.ischardev(fp::AbstractPath) = ischardev(mode(fp))
@@ -887,4 +887,3 @@ macro __INCLUDE__()
887887
m.include(mapexpr::Function, path::AbstractPath) = Base.include(mapexpr, m, path)
888888
end
889889
end
890-

src/system.jl

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ julia> mode(p"src/FilePathsBase.jl")
6666
-rw-r--r--
6767
```
6868
"""
69-
mode(fp::SystemPath) = stat(fp).mode
70-
Base.filesize(fp::SystemPath) = stat(fp).size
69+
mode(fp::SystemPath) = Mode(stat(string(fp)).mode)
70+
Base.filesize(fp::SystemPath) = stat(string(fp)).size
7171

7272
"""
7373
modified(fp::SystemPath) -> DateTime
@@ -80,7 +80,7 @@ julia> modified(p"src/FilePathsBase.jl")
8080
2017-06-20T04:01:09
8181
```
8282
"""
83-
modified(fp::SystemPath) = stat(fp).mtime
83+
modified(fp::SystemPath) = unix2datetime(stat(string(fp)).mtime)
8484

8585
"""
8686
created(fp::SystemPath) -> DateTime
@@ -93,7 +93,7 @@ julia> created(p"src/FilePathsBase.jl")
9393
2017-06-20T04:01:09
9494
```
9595
"""
96-
created(fp::SystemPath) = stat(fp).ctime
96+
created(fp::SystemPath) = unix2datetime(stat(string(fp)).ctime)
9797
Base.isdir(fp::SystemPath) = isdir(mode(fp))
9898
Base.isfile(fp::SystemPath) = isfile(mode(fp))
9999
Base.islink(fp::SystemPath) = islink(lstat(fp).mode)
@@ -108,14 +108,15 @@ Base.isblockdev(fp::SystemPath) = isblockdev(mode(fp))
108108
Returns whether the `path` is executable for the current user.
109109
"""
110110
function isexecutable(fp::SystemPath)
111-
s = stat(fp)
111+
s = stat(string(fp))
112+
mode = Mode(s.mode)
112113
usr = User()
113114

114115
return (
115-
isexecutable(s.mode, :ALL) ||
116-
isexecutable(s.mode, :OTHER) ||
117-
(usr.uid == s.user.uid && isexecutable(s.mode, :USER)) ||
118-
(usr.gid == s.group.gid && isexecutable(s.mode, :GROUP))
116+
isexecutable(mode, :ALL) ||
117+
isexecutable(mode, :OTHER) ||
118+
(usr.uid == s.uid && isexecutable(mode, :USER)) ||
119+
(usr.gid == s.gid && isexecutable(mode, :GROUP))
119120
)
120121
end
121122

@@ -125,14 +126,15 @@ end
125126
Returns whether the `path` is writable for the current user.
126127
"""
127128
function Base.iswritable(fp::SystemPath)
128-
s = stat(fp)
129+
s = stat(string(fp))
130+
mode = Mode(s.mode)
129131
usr = User()
130132

131133
return (
132-
iswritable(s.mode, :ALL) ||
133-
iswritable(s.mode, :OTHER) ||
134-
(usr.uid == s.user.uid && iswritable(s.mode, :USER)) ||
135-
(usr.gid == s.group.gid && iswritable(s.mode, :GROUP))
134+
iswritable(mode, :ALL) ||
135+
iswritable(mode, :OTHER) ||
136+
(usr.uid == s.uid && iswritable(mode, :USER)) ||
137+
(usr.gid == s.gid && iswritable(mode, :GROUP))
136138
)
137139
end
138140

@@ -142,23 +144,24 @@ end
142144
Returns whether the `path` is readable for the current user.
143145
"""
144146
function Base.isreadable(fp::SystemPath)
145-
s = stat(fp)
147+
s = stat(string(fp))
148+
mode = Mode(s.mode)
146149
usr = User()
147150

148151
return (
149-
isreadable(s.mode, :ALL) ||
150-
isreadable(s.mode, :OTHER) ||
151-
(usr.uid == s.user.uid && isreadable(s.mode, :USER)) ||
152-
(usr.gid == s.group.gid && isreadable(s.mode, :GROUP))
152+
isreadable(mode, :ALL) ||
153+
isreadable(mode, :OTHER) ||
154+
(usr.uid == s.uid && isreadable(mode, :USER)) ||
155+
(usr.gid == s.gid && isreadable(mode, :GROUP))
153156
)
154157
end
155158

156159
function Base.ismount(fp::SystemPath)
157160
isdir(fp) || return false
158-
s1 = lstat(fp)
161+
s1 = lstat(string(fp))
159162
# Symbolic links cannot be mount points
160163
islink(fp) && return false
161-
s2 = lstat(parent(fp))
164+
s2 = lstat(string(parent(fp)))
162165
# If a directory and its parent are on different devices, then the
163166
# directory must be a mount point
164167
(s1.device != s2.device) && return true

0 commit comments

Comments
 (0)