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

extmod/vfs_fat: Checks for remove() and rmdir(). #2463

Closed
wants to merge 2 commits into from
Closed

extmod/vfs_fat: Checks for remove() and rmdir(). #2463

wants to merge 2 commits into from

Conversation

hosaka
Copy link
Contributor

@hosaka hosaka commented Sep 28, 2016

Please note, I haven't run the tests on this yet.
I noticed the TODOs when I was working on the last PR.

I've split the unlink function to avoid repeating the code. From what I see, there is no fatfs attribute that tells us it's a file, i.e if it's not a directory it's a file (example of readdir()).

I am planning to continue to improve the coverage of vfs_fat.c after this approved/discarded.

@hosaka hosaka changed the title extmod/vfs_fat: Checks for remove() and rmdir(). extmod/vfs_fat: Checks for remove() and rmdir(). WIP Sep 28, 2016
except OSerror as e:
assert e.args[0] == uerrno.ENOTDIR
except OSError as e:
assert e.args[0] == 20 # ENOTDIR
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moduerrno.c does have EISDIR but doesn't have ENOTDIR error definition, can this be added to the common list?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not to write a test, sorry ;-). We don't want testsuite to bloat production builds ;-). (So, it can be added - when many (at least few) people report good usecases for having it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very reasonable! I will keep the "20" and a comment for the time being :)

@hosaka hosaka changed the title extmod/vfs_fat: Checks for remove() and rmdir(). WIP extmod/vfs_fat: Checks for remove() and rmdir(). Oct 2, 2016
@hosaka
Copy link
Contributor Author

hosaka commented Oct 6, 2016

I have squashed the commits and changed the asserts to prints, including the existing ones.

Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

It looks like you can combine the f_stat functionality for both remove and rmdir. You just need a flag as an argument to the common functionto check if it is/isn't a dir. Eg:

if ((fno.fattrib & AM_DIR) == wanted_attr) {
    return unlink;
} else {
    raise exception;
}

and wanted_attr would be 0 for remove and AM_DIR for rmdir.

Also, for the changes to the tests that turn assert to print, please split that into a separate patch, thanks.

return fat_vfs_unlink(path);
} else {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
MP_OBJ_NEW_SMALL_INT(EISDIR)));
Copy link
Member

Choose a reason for hiding this comment

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

This can fit on one line (it's less than 100 chars).

Copy link
Member

Choose a reason for hiding this comment

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

Please use MP_EISDIR.

@hosaka
Copy link
Contributor Author

hosaka commented Oct 7, 2016

Thanks for the suggestions Damien! I've combined the f_stat checks in the unlink function. I didn't want to just pass 0 as an attribute, so !AM_DIR will always resolve to 0 instead.

I will submit a separate patch for asserts to prints before I carry on with more vfs_fat test coverage once this PR is closed.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 9, 2016

I'd find introduction of a function named fat_vfs_unlink() to be confusing. In ANSI C/POSIX, remove() and unlink() are similar, but slightly different, and difference is the opposite of what fat_vfs_remove() vs fat_vfs_unlink() do. We don't implement unlink(), and from all the above, there's no reason to have fat_vfs_unlink() function. If you need to factor internal work function for fat_vfs_remove(), please call it fat_vfs_remove_internal().

I didn't want to just pass 0 as an attribute, so !AM_DIR will always resolve to 0 instead.

And yet "attribute" is numeric, even bitmask value, while !AM_DIR is a boolean. Using the latter instead of the former is quite confusing. If you need zero attribute value, please use just that (feel free to add comment if you'd like to clarify something regarding it).

@hosaka
Copy link
Contributor Author

hosaka commented Oct 9, 2016

Hi Paul, thanks for the suggestions. You're quite right about the attribute, I will change it to a zero and add a comment instead.

Regarding the function name, in some modules, functions like path_equal() in vfs don't follow a naming convention, which is good and bad at the same time, it shows that they don't belong to the module but also have a freeform name. Perhaps having a underscore prefix for local functions only could be a good convention? I will rename the function as you suggested.

@dhylands
Copy link
Contributor

dhylands commented Oct 9, 2016

In C, all symbols with leading underscores are reserved for the runtime library.
https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
so it is best to avoid those.

@hosaka
Copy link
Contributor Author

hosaka commented Oct 9, 2016

Oh yes, I completely forgot about that, seeing it being used in python!

@dpgeorge
Copy link
Member

Merged in d02f3a5 and f274561 with some minor changes to reduce code size (mp_obj_str_get_str only called once in remove_internal, instead of in remove and rmdir).

Thanks, please proceed with next parts!

@dpgeorge dpgeorge closed this Oct 11, 2016
@hosaka
Copy link
Contributor Author

hosaka commented Oct 11, 2016

Thanks Damien, I'll be looking into more vfs coverage from now on.

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants