{"action":"created","comment":{"url":"https://api.github.com/repos/micropython/micropython/pulls/comments/64925530","id":64925530,"diff_hunk":"@@ -111,22 +113,127 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {\n     switch (res) {\n         case FR_OK:\n             return mp_const_none;\n-        case FR_EXIST:\n-            // TODO should be FileExistsError\n-            nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, \"File exists: '%s'\", path));\n         default:\n-            nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, \"Error creating directory '%s'\", path));\n+            nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,\n+                MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));\n     }\n }\n STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir);\n \n+STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_o) {\n+    (void)vfs_in;\n+    const char *path = mp_obj_str_get_str(path_o);\n+    FRESULT res = f_chdir(path);\n+    switch (res) {\n+        case FR_OK:\n+            return mp_const_none;\n+        default:\n+            nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,\n+                MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));\n+    }\n+}\n+STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_chdir_obj, fat_vfs_chdir);\n+\n+// Checks for path equality, ignoring trailing slashes:\n+//   path_equal(/, /) -> true\n+// second argument must be in canonical form (meaning no trailing slash, unless it's just /)\n+STATIC bool path_equal(const char *path, const char *path_canonical) {\n+    while (*path_canonical != '\\0' && *path == *path_canonical) {\n+        ++path;\n+        ++path_canonical;\n+    }\n+    if (*path_canonical != '\\0') {\n+        return false;\n+    }\n+    while (*path == '/') {\n+        ++path;\n+    }\n+    return *path == '\\0';\n+}\n+\n+/// \\function stat(path)\n+/// Get the status of a file or directory.\n+STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {\n+    (void)vfs_in;\n+    const char *path = mp_obj_str_get_str(path_in);\n+\n+    FILINFO fno;\n+#if _USE_LFN\n+    fno.lfname = NULL;\n+    fno.lfsize = 0;\n+#endif\n+\n+    FRESULT res;\n+    if (path_equal(path, \"/\")) {\n+        // stat root directory\n+\tfno.fsize = 0;\n+\tfno.fdate = 0;\n+\tfno.ftime = 0;\n+\tfno.fattrib = AM_DIR;\n+    } else {\n+        res = FR_NO_PATH;\n+        for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {\n+            fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];\n+            if (vfs != NULL && path_equal(path, vfs->str)) {\n+                // stat mounted device directory\n+                fno.fsize = 0;\n+                fno.fdate = 0;\n+                fno.ftime = 0;\n+                fno.fattrib = AM_DIR;\n+                res = FR_OK;\n+            }\n+        }\n+        if (res == FR_NO_PATH) {\n+            // stat normal file\n+            res = f_stat(path, &fno);\n+        }\n+        if (res != FR_OK) {\n+            nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,\n+                MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));\n+        }\n+    }\n+\n+    mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));\n+    mp_int_t mode = 0;\n+    if (fno.fattrib & AM_DIR) {\n+        mode |= 0x4000; // stat.S_IFDIR\n+    } else {\n+        mode |= 0x8000; // stat.S_IFREG\n+    }\n+    mp_int_t seconds = timeutils_seconds_since_2000(\n+        1980 + ((fno.fdate >> 9) & 0x7f),\n+        (fno.fdate >> 5) & 0x0f,\n+        fno.fdate & 0x1f,\n+        (fno.ftime >> 11) & 0x1f,\n+        (fno.ftime >> 5) & 0x3f,\n+        2 * (fno.ftime & 0x1f)\n+    );\n+    t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode\n+    t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino\n+    t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev\n+    t->items[3] = MP_OBJ_NEW_SMALL_INT(0); // st_nlink\n+    t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid\n+    t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid\n+    t->items[6] = MP_OBJ_NEW_SMALL_INT(fno.fsize); // st_size\n+    t->items[7] = MP_OBJ_NEW_SMALL_INT(seconds); // st_atime\n+    t->items[8] = MP_OBJ_NEW_SMALL_INT(seconds); // st_mtime\n+    t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime\n+\n+    return (mp_obj_t)t;","path":"extmod/vfs_fat.c","position":151,"original_position":151,"commit_id":"172a3fb51f31f4789e385828c57326417ecc8cdc","original_commit_id":"172a3fb51f31f4789e385828c57326417ecc8cdc","user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"body":"@robert-hh you need to write it like this: `return MP_OBJ_FROM_PTR(t);`","created_at":"2016-05-27T15:47:35Z","updated_at":"2016-05-27T15:47:35Z","html_url":"https://github.com/micropython/micropython/pull/2110#discussion_r64925530","pull_request_url":"https://api.github.com/repos/micropython/micropython/pulls/2110","_links":{"self":{"href":"https://api.github.com/repos/micropython/micropython/pulls/comments/64925530"},"html":{"href":"https://github.com/micropython/micropython/pull/2110#discussion_r64925530"},"pull_request":{"href":"https://api.github.com/repos/micropython/micropython/pulls/2110"}}},"pull_request":{"url":"https://api.github.com/repos/micropython/micropython/pulls/2110","id":71420321,"html_url":"https://github.com/micropython/micropython/pull/2110","diff_url":"https://github.com/micropython/micropython/pull/2110.diff","patch_url":"https://github.com/micropython/micropython/pull/2110.patch","issue_url":"https://api.github.com/repos/micropython/micropython/issues/2110","number":2110,"state":"closed","locked":false,"title":"esp8266: Add stat(), chdir() and rmdir() to module uos and vfs","user":{"login":"robert-hh","id":12476868,"avatar_url":"https://avatars.githubusercontent.com/u/12476868?v=3","gravatar_id":"","url":"https://api.github.com/users/robert-hh","html_url":"https://github.com/robert-hh","followers_url":"https://api.github.com/users/robert-hh/followers","following_url":"https://api.github.com/users/robert-hh/following{/other_user}","gists_url":"https://api.github.com/users/robert-hh/gists{/gist_id}","starred_url":"https://api.github.com/users/robert-hh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robert-hh/subscriptions","organizations_url":"https://api.github.com/users/robert-hh/orgs","repos_url":"https://api.github.com/users/robert-hh/repos","events_url":"https://api.github.com/users/robert-hh/events{/privacy}","received_events_url":"https://api.github.com/users/robert-hh/received_events","type":"User","site_admin":false},"body":"    esp8266/moduos.c:\r\n        added proxy stubs for stat() and chdir(), and an alias for rmdir()\r\n    extmod/vfs_fat.c:\r\n        - added the functions fo stat() and chdir() and an alias for rmdir()\r\n        - replaced the text error messages by the Posix error numbers using\r\n          the mechanism already provided","created_at":"2016-05-25T16:15:07Z","updated_at":"2016-05-27T15:47:35Z","closed_at":"2016-05-27T12:34:47Z","merged_at":null,"merge_commit_sha":"2692afada2c606157403551af1efa77a95d574fc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/micropython/micropython/pulls/2110/commits","review_comments_url":"https://api.github.com/repos/micropython/micropython/pulls/2110/comments","review_comment_url":"https://api.github.com/repos/micropython/micropython/pulls/comments{/number}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/2110/comments","statuses_url":"https://api.github.com/repos/micropython/micropython/statuses/172a3fb51f31f4789e385828c57326417ecc8cdc","head":{"label":"robert-hh:master","ref":"master","sha":"172a3fb51f31f4789e385828c57326417ecc8cdc","user":{"login":"robert-hh","id":12476868,"avatar_url":"https://avatars.githubusercontent.com/u/12476868?v=3","gravatar_id":"","url":"https://api.github.com/users/robert-hh","html_url":"https://github.com/robert-hh","followers_url":"https://api.github.com/users/robert-hh/followers","following_url":"https://api.github.com/users/robert-hh/following{/other_user}","gists_url":"https://api.github.com/users/robert-hh/gists{/gist_id}","starred_url":"https://api.github.com/users/robert-hh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robert-hh/subscriptions","organizations_url":"https://api.github.com/users/robert-hh/orgs","repos_url":"https://api.github.com/users/robert-hh/repos","events_url":"https://api.github.com/users/robert-hh/events{/privacy}","received_events_url":"https://api.github.com/users/robert-hh/received_events","type":"User","site_admin":false},"repo":null},"base":{"label":"micropython:master","ref":"master","sha":"751e3b7a820c13561cca47717d47d7784f776232","user":{"login":"micropython","id":6298560,"avatar_url":"https://avatars.githubusercontent.com/u/6298560?v=3","gravatar_id":"","url":"https://api.github.com/users/micropython","html_url":"https://github.com/micropython","followers_url":"https://api.github.com/users/micropython/followers","following_url":"https://api.github.com/users/micropython/following{/other_user}","gists_url":"https://api.github.com/users/micropython/gists{/gist_id}","starred_url":"https://api.github.com/users/micropython/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micropython/subscriptions","organizations_url":"https://api.github.com/users/micropython/orgs","repos_url":"https://api.github.com/users/micropython/repos","events_url":"https://api.github.com/users/micropython/events{/privacy}","received_events_url":"https://api.github.com/users/micropython/received_events","type":"Organization","site_admin":false},"repo":{"id":15337142,"name":"micropython","full_name":"micropython/micropython","owner":{"login":"micropython","id":6298560,"avatar_url":"https://avatars.githubusercontent.com/u/6298560?v=3","gravatar_id":"","url":"https://api.github.com/users/micropython","html_url":"https://github.com/micropython","followers_url":"https://api.github.com/users/micropython/followers","following_url":"https://api.github.com/users/micropython/following{/other_user}","gists_url":"https://api.github.com/users/micropython/gists{/gist_id}","starred_url":"https://api.github.com/users/micropython/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micropython/subscriptions","organizations_url":"https://api.github.com/users/micropython/orgs","repos_url":"https://api.github.com/users/micropython/repos","events_url":"https://api.github.com/users/micropython/events{/privacy}","received_events_url":"https://api.github.com/users/micropython/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/micropython/micropython","description":"MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems","fork":false,"url":"https://api.github.com/repos/micropython/micropython","forks_url":"https://api.github.com/repos/micropython/micropython/forks","keys_url":"https://api.github.com/repos/micropython/micropython/keys{/key_id}","collaborators_url":"https://api.github.com/repos/micropython/micropython/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/micropython/micropython/teams","hooks_url":"https://api.github.com/repos/micropython/micropython/hooks","issue_events_url":"https://api.github.com/repos/micropython/micropython/issues/events{/number}","events_url":"https://api.github.com/repos/micropython/micropython/events","assignees_url":"https://api.github.com/repos/micropython/micropython/assignees{/user}","branches_url":"https://api.github.com/repos/micropython/micropython/branches{/branch}","tags_url":"https://api.github.com/repos/micropython/micropython/tags","blobs_url":"https://api.github.com/repos/micropython/micropython/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/micropython/micropython/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/micropython/micropython/git/refs{/sha}","trees_url":"https://api.github.com/repos/micropython/micropython/git/trees{/sha}","statuses_url":"https://api.github.com/repos/micropython/micropython/statuses/{sha}","languages_url":"https://api.github.com/repos/micropython/micropython/languages","stargazers_url":"https://api.github.com/repos/micropython/micropython/stargazers","contributors_url":"https://api.github.com/repos/micropython/micropython/contributors","subscribers_url":"https://api.github.com/repos/micropython/micropython/subscribers","subscription_url":"https://api.github.com/repos/micropython/micropython/subscription","commits_url":"https://api.github.com/repos/micropython/micropython/commits{/sha}","git_commits_url":"https://api.github.com/repos/micropython/micropython/git/commits{/sha}","comments_url":"https://api.github.com/repos/micropython/micropython/comments{/number}","issue_comment_url":"https://api.github.com/repos/micropython/micropython/issues/comments{/number}","contents_url":"https://api.github.com/repos/micropython/micropython/contents/{+path}","compare_url":"https://api.github.com/repos/micropython/micropython/compare/{base}...{head}","merges_url":"https://api.github.com/repos/micropython/micropython/merges","archive_url":"https://api.github.com/repos/micropython/micropython/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/micropython/micropython/downloads","issues_url":"https://api.github.com/repos/micropython/micropython/issues{/number}","pulls_url":"https://api.github.com/repos/micropython/micropython/pulls{/number}","milestones_url":"https://api.github.com/repos/micropython/micropython/milestones{/number}","notifications_url":"https://api.github.com/repos/micropython/micropython/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/micropython/micropython/labels{/name}","releases_url":"https://api.github.com/repos/micropython/micropython/releases{/id}","deployments_url":"https://api.github.com/repos/micropython/micropython/deployments","created_at":"2013-12-20T11:47:07Z","updated_at":"2016-05-27T14:01:50Z","pushed_at":"2016-05-27T13:33:11Z","git_url":"git://github.com/micropython/micropython.git","ssh_url":"git@github.com:micropython/micropython.git","clone_url":"https://github.com/micropython/micropython.git","svn_url":"https://github.com/micropython/micropython","homepage":"","size":63938,"stargazers_count":3238,"watchers_count":3238,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":649,"mirror_url":null,"open_issues_count":247,"forks":649,"open_issues":247,"watchers":3238,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/micropython/micropython/pulls/2110"},"html":{"href":"https://github.com/micropython/micropython/pull/2110"},"issue":{"href":"https://api.github.com/repos/micropython/micropython/issues/2110"},"comments":{"href":"https://api.github.com/repos/micropython/micropython/issues/2110/comments"},"review_comments":{"href":"https://api.github.com/repos/micropython/micropython/pulls/2110/comments"},"review_comment":{"href":"https://api.github.com/repos/micropython/micropython/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/micropython/micropython/pulls/2110/commits"},"statuses":{"href":"https://api.github.com/repos/micropython/micropython/statuses/172a3fb51f31f4789e385828c57326417ecc8cdc"}}}}
{"actor":{"display_login":"dpgeorge"}}