pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.51k stars 380 forks source link

Strongly-typed accessor for FileStat #589

Closed liori closed 3 months ago

liori commented 3 months ago

For the purposes of this PR it would be nice if sftp offered a strongly-typed accessor for the sftp.FileStat structure.

Would it be possible for the fileInfoFromStat function to return something assignable to os.FileInfo, but also offering a method to access the stat field without having to convert from interface{}?

puellanivis commented 3 months ago

The Sys() function signature is already defined by the os.FileInfo interface. And there’s not really a strong reason why we would want to provide Yet Another Accessor, when type assertion works just fine to unwrap the interface{}.

puellanivis commented 3 months ago

Thinking about this a little more. It wouldn’t even be particularly useful, as one would need to type-assert from the os.FileInfo into an interface{ FileStat() *sftp.FileStat } in order to access the proposed typed return anyways.

puellanivis commented 3 months ago

I’m going to go ahead and close this as we have no intent to provide such a function, and even after providing such a function, a type inference would still be necessary.