Skip to content
Snippets Groups Projects
Commit b5b76546 authored by Alexander Turenko's avatar Alexander Turenko Committed by Igor Munkin
Browse files

lua: split fio to minifio and fio

The minifio module is supposed to be used in tarantool's code that
potentially works at early initialization stage.

The loaders.lua module needs several file manipulation functions and
it'll be moved to the early initialization stage (see the previous
commit for the idea).

Next commits will use minifio instead of fio in loaders.lua and will
move minifio and loaders at the early loading stage.

The list of changes in the functions:

* fio.pathjoin() uses `error(<...>, 0)` to don't prefix the error
  message with `internal.minifio.lua` -- a user is unlikely interested
  how fio is split to files internally.
* An obsoleted comment from fio.abspath() is dropped (it is obsoleted by
  commit 583e8ba2 ("fio: new approach for error handling")).

cwd(), pathjoin() and abspath() are moved to `minifio` and exposed from
`fio`. dirname() is duplicated: `minifio`'s implementation uses
ffi.new(), `fio`'s implementation uses cord_ibuf_take()/cord_ibuf_put().

## Alternatives considered

In brief: no really good option, but the implemented one looks as the
best one.

### Copy to loaders.lua

First option is to copy those four functions right into loaders.lua. It
requires a slight adaptation:

- cwd(): reimplement using ffi.
- pathjoin(): just copy.
- abspath(): copy and use own cwd() and pathjoin().
- dirname(): copy and use ffi.new() instead of
  cord_ibuf_take()/cord_ibuf_put().

All the functions would be maintained in two places that is error-prone.
It would be good to reduce amount of copies of the same/similar code.

### Add minifio.lua

Okay, let's assume we created own file for the four functions. Can we
avoid adding minifio.c for cwd()? There are two ways (spoiler: both are
bad).

* We can initialize the C part of `fio` before minifio.lua and use it
  here. But it would be highly counter-intuitive to use `fio` in
  `minifio`.
* We can reimplement cwd() on ffi, but we'll need to duplicate abspath()
  to use `minifio`'s cwd() function.

We definitely need `minifio.c`.

### Add minifio.c and minifio.lua

This option is implemented in this commit. The only function that is
duplicated is dirname().

### Mitigate dirname() duplication

There are two ways.

It is possible to add a dependency on the `buffer` module and use
cord_ibuf_take()/cord_ibuf_put() in `minifio`. However it would mean
that `buffer` shouldn't depend on other built-in modules. It is logical
for `minifio`, which is created specifically to load at early stage, but
counter-intuitive for `buffer`. If `buffer` will depend on another
built-in module in a future, a developer will need to play around
'right' order of loading.

We can also move dirname()'s implementation to the C part of `minifio`,
use C's cord_ibuf_take()/cord_ibuf_put() and expose the function as to
`minifio` as well as to `fio`.

The latter is a good option, but I don't bother much about the
copy-paste, because the function body has 7 SLoC.

### Move into Lua C API

We can implement all the four function using the Lua C API in fio.c and
initialize the C part of `fio` before loading of loaders.lua.

It would look more clean in some sense: all the file manipulation
functions are in the `fio` module. However it is also error-prone,
because nothing would stop a future developer to use some fio.foobar()
function, which is actually loaded after loaders.lua, before loading
Lua's part of `fio`.

An explicit splitting to early/usual stage looks safer.

Part of #7774

NO_TEST=no user visible changes
NO_CHANGELOG=see NO_TEST
NO_DOC=see NO_TEST
parent 43274526
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment