codetainerapp / codetainer

A Docker container in your browser.
MIT License
1.05k stars 108 forks source link

Listing files of container returns wrong response #28

Closed david50407 closed 8 years ago

david50407 commented 8 years ago

When I execute /codetainer/utils/files -s / inside the contianer, it returns correct answer, as the screenshot below:

BUT, when I list files by codetainer API, it returns only with correct filename but wrong file info (is_dir, is_link, modified_time, etc.), as the screenshot shown below:

david50407 commented 8 years ago

After using the code below to test actions of json.Marshal and json.Unmarshal:

package main

import (
        "encoding/json"
        "fmt"
)

type Foo struct {
        Apple string `json:"field1"`
        Banana string `json:"field2"`
}

func main() {
        var f Foo
        str := `{ "Apple": "app", "field2": "ban" }`
        json.Unmarshal([]byte(str), &f)
        fmt.Println(f)
        s, err := json.Marshal(f)
        if err != nil {
                fmt.Println("err")
        }
        fmt.Println(string(s))
}

We can found that the output is

{ ban}
{"field1":"","field2":"ban"}

It means when we set the tag for json field name, json.Unmarshal will decode by the name we set. So, the struct defination here https://github.com/codetainerapp/codetainer/blob/0cf7cdf084ab2d28a04b3c8329782618823c480a/models.go#L375 cause losing the file info when we unmarshal the file list from util/files here https://github.com/codetainerapp/codetainer/blob/0cf7cdf084ab2d28a04b3c8329782618823c480a/models.go#L396 .

jandre commented 8 years ago

wonderful! Thank you for this fix.