Skip to content
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

Add file.stat() to query file/directory attributes. #1724

Merged
merged 2 commits into from
Jan 17, 2017

Conversation

devsaurus
Copy link
Member

Augments to #1321.

  • This PR is for the dev branch rather than for master.
  • This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • I have thoroughly tested my contribution.
  • The code changes are reflected in the documentation at docs/en/*.

New function file.stat() retrieves file/directory attributes in a table:

  • file name
  • file size
  • time stamp
  • flags for file/dir, read-only, hidden, system, archive

Works on both SPIFFS and FatFs, with SPIFFS providing meaningful information only for name and size (other items are present but default).

@devsaurus devsaurus mentioned this pull request Jan 14, 2017
4 tasks
@@ -13,6 +13,14 @@

#define FILE_READ_CHUNK 1024

// use this time/date in absence of a timestamp
#define FILE_TIMEDEF_YEAR 2016
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I recommend using a more common value for the epoch? E.g. the Unix epoch (Jan 1, 1970) or ZigBee (Jan 1, 2000).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the Unix epoch is used now as default.

lua_pushstring( L, key );
lua_pushboolean( L, b );
lua_rawset( L, -3 );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead/for all of the above helpers, why not use lua_setfield()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of this function, changed.


- `size` file size in bytes
- `name` file name
- `time` table with time stamp information. Default is 2016-06-21 00:00:00 in case time stamps are not supported (on SPIFFS).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget this if changing the epoch...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@marcelstoer
Copy link
Member

Wouldn't that make sense for the OO API as well: file.obj:stat()?

@devsaurus
Copy link
Member Author

Wouldn't that make sense for the OO API as well: file.obj:stat()

This would be more like an fstat() (i.e. performing stat() on an opened file). But that's not supported by FatFS, therefore I just implemented stat() for a path for now.

@marcelstoer marcelstoer added this to the 2.0.0 milestone Jan 17, 2017
@marcelstoer marcelstoer merged commit 305d7c4 into nodemcu:dev Jan 17, 2017
@devsaurus devsaurus deleted the file_stat branch January 21, 2017 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants