time.Time has no field or method UTC -> error

850 views
Skip to first unread message

Xan

unread,
Jul 8, 2013, 7:53:13 AM7/8/13
to golan...@googlegroups.com
Hi,

I have this code: http://play.golang.org/p/J2GSPJrGu7

When I compile I receive the strange error:

$ go build walk.go
# command-line-arguments
./walk.go:11: imported and not used: "time"
./walk.go:49: modtime.UTC undefined (type func() time.Time has no field or method UTC)


It's suppossed that time.Time has UTC() func, isn't?

What is my error?

Thanks,
Xan.

Dominik Honnef

unread,
Jul 8, 2013, 8:05:51 AM7/8/13
to golan...@googlegroups.com
Xan <xanc...@gmail.com> writes:

> Hi,
>
> I have this code: http://play.golang.org/p/J2GSPJrGu7
>
> When I compile I receive the strange error:
>
> $ go build walk.go
> # command-line-arguments
> ./walk.go:11: imported and not used: "time"

You're never directly using the time package, only transitively.

> ./walk.go:49: modtime.UTC undefined (type func() time.Time has no field or
> method UTC)

(os.FileInfo).ModTime() is a method, not a field. By doing `modtime :=
info.ModTime`, you're assigning a method to modtime, not the return
value of ModTime(), which would indeed be a time.Time and have a UTC()
method on it.

Xan

unread,
Jul 9, 2013, 5:05:19 AM7/9/13
to golan...@googlegroups.com
And so, how can I do that?

El dilluns 8 de juliol de 2013 14:05:51 UTC+2, Dominik Honnef va escriure:

Jan Mercl

unread,
Jul 9, 2013, 5:11:15 AM7/9/13
to Xan, golang-nuts
On Tue, Jul 9, 2013 at 11:05 AM, Xan <xanc...@gmail.com> wrote:
> And so, how can I do that?

IDK what the code should do, however perhaps:
http://play.golang.org/p/p8cZAD_ZCs

-j

xancorreu

unread,
Jul 9, 2013, 10:52:03 AM7/9/13
to Jan Mercl, golang-nuts
Al 09/07/13 11:11, En/na Jan Mercl ha escrit:
Thanks a lot,
Xan.

xancorreu

unread,
Jul 9, 2013, 11:09:17 AM7/9/13
to Jan Mercl, golang-nuts
Al 09/07/13 11:11, En/na Jan Mercl ha escrit:
I put changes in this repo:
https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go
but when I run it (after compile it), I get:

File: README.textile, Hash:
d73ced1d17a2247bb6d09a334e515f12905197b42ef42b7c453d04c419394721, Hash
reading size: 100, File size: 1376, File modification time: May 9, 2013
at 6:37pm (UTC), File permissions: -rw-r--r--

but
$ sha224sum README.textile
1043ba66ecc30d96c02e88b53479990b01cc5df27e11a3c2f9486c49 README.textile

So why the golang sha224 does not produce the same as bash sha224?

Thanks,
Xan.


Maxim Khitrov

unread,
Jul 9, 2013, 11:22:42 AM7/9/13
to xancorreu, golang-nuts
walk.go is using sha256, not 224.

xancorreu

unread,
Jul 9, 2013, 2:22:27 PM7/9/13
to Maxim Khitrov, golang-nuts
Al 09/07/13 17:22, En/na Maxim Khitrov ha escrit:
Equal:
[xan@gerret find-duplicated-files]$ sha256sum README.textile
c025efd3e818cb3469ca4228d812f907e2563de56b7d1d717c1d46b73b08168f
README.textile
[xan@gerret find-duplicated-files]$

So, there are different hashes. What's wrong?

Xan.

Maxim Khitrov

unread,
Jul 9, 2013, 2:34:19 PM7/9/13
to xancorreu, golang-nuts
This is not correct:

data := make([]byte, 100)
count, error := file.Read(data)
...
funcio.Write(data)

First, you're reading at most 100 bytes from the file. If the file is
bigger, the rest is not included in the hash. If the file is exactly
100 bytes, Read is not guaranteed to return all of them in a single
call. If the file is smaller, you're writing a bunch of zeros into the
hash, which aren't part of the data returned by file.Read. You should
be using funcio.Write(data[:count]) instead and doing this in a loop
until Read returns io.EOF.

You can use ioutil.ReadFile to make your life easier, but it's not
ideal for large files.

xancorreu

unread,
Jul 10, 2013, 6:53:21 AM7/10/13
to Maxim Khitrov, golang-nuts
Al 09/07/13 20:34, En/na Maxim Khitrov ha escrit:
Thanks, Maxim, for detecting my error.

> You should
> be using funcio.Write(data[:count]) instead and doing this in a loop
> until Read returns io.EOF.

How can I do that? Can you put some code? I'm a newbee.

Thanks, another time.
Xan.

xancorreu

unread,
Jul 10, 2013, 7:06:05 AM7/10/13
to Maxim Khitrov, golang-nuts
Al 09/07/13 20:34, En/na Maxim Khitrov ha escrit:
> Maxim Khitrov
Done: https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go
Message has been deleted

xancorreu

unread,
Jul 10, 2013, 8:02:36 AM7/10/13
to Johann Höchtl, golan...@googlegroups.com
Thanks for the hint. At the other hand, there is any other security "flags" in my code: https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go ?

Thanks,
Xan.

Al 10/07/13 13:43, En/na Johann Höchtl ha escrit:
possibly dangerous

if !!fi.IsDir()  // mind the double-negation

but that was not the point anyway. Couldn't resist
Reply all
Reply to author
Forward
Message has been deleted
0 new messages