-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Add fileStat to tpl/os/os #5036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tpl/os/os.go
Outdated
@@ -130,3 +130,22 @@ func (ns *Namespace) FileExists(i interface{}) (bool, error) { | |||
|
|||
return status, nil | |||
} | |||
|
|||
// FileStat Stat returns the os.FileInfo structure describing file. | |||
func (ns *Namespace) FileStat(i interface{}) (_os.FileInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name it simply os.Stat
. I think we (at least has tried) to name the other funcs that more or less wraps the std lib variant with the same name as the original. In this case I think that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
I have renamed the name.
tpl/os/init.go
Outdated
@@ -55,6 +55,13 @@ func init() { | |||
}, | |||
) | |||
|
|||
ns.AddMethodMapping(ctx.FileStat, | |||
[]string{"fileStat"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to rename here?, @bep
In my opinion, fileStat
will be better than Stat
because we cannot get what kind of stat if Stat
is used in Hugo template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove it. We don't need an alias for this, as os.Stat
is already short enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, I did not know we can directly access os
like {{ os.Stat "filepath"}}
even in Hugo template.
You are right. I have removed it.
In this case, Should I update docs or not?
I mean, is it better to close this or fix it?
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Add
fileStat
method toos
fileStat PATH
returnsos.FileInfo
Use Case
Method
readFile
has the size limitation (1MB).To avoid throwing the error and make a workaround, the size must be got before executing
readFile
.Under the current condition, this can be done via
[]os.FileInfo
as a result ofreadDir
.However, it is a little complicated because you have to handle an array even though you need just a single
os.FileInfo
.fileStat
is useful in such situations.