move (almost) all I/O under Util::Pathname by xworld21 · Pull Request #2640 · brucemiller/LaTeXML · GitHub
Skip to content

move (almost) all I/O under Util::Pathname - #2640

Open
xworld21 wants to merge 19 commits into
brucemiller:masterfrom
xworld21:pathname-io
Open

xworld21 wants to merge 19 commits into
brucemiller:masterfrom
xworld21:pathname-io

Conversation

@xworld21

Copy link
Copy Markdown
Contributor

This is an attempt at refactoring all I/O calls that deal with file/directory names through wrapper functions in Util::Pathname. This means all the -X tests, open, opendir, stat, and unlink. There might be others I did not catch.

My goal is to guarantee that normal LaTeXML code is never exposed to raw file names, which are not Unicode strings and must be decoded and encoded before use. The enconding and decoding will be done in the wrapper functions, although not yet – I first want to know if this refactor is ok.

(The encoding and decoding itself is simple, see #2545 for Unix using Encode::Locale. For Windows, I concluded that the only way to go is Win32::LongPath.)

@brucemiller

Copy link
Copy Markdown
Owner

@dginev dginev left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am lightly concerned about the performance loss (many new function calls), but if the consistency is worthwhile that is likely fine. We only manage on the order of hundreds of files in a single conversion run.

The names of the new functions are fine actually - they fit the other pathname_* functions. If we wanted to be explicit that these are file test we can consider adding a _filetest_ piece. So pathname_filetest_r. Or we can go even shorter and do filetest_r? But if we were to add a new term, I'd use the one from the perl documentation.

Comment thread lib/LaTeXML/Util/Pathname.pm Outdated
@dginev

dginev commented Oct 15, 2025

Copy link
Copy Markdown
Collaborator

Also, could you please rebase the PR to the master branch? Windows CI should be passing again.

@dginev dginev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Circling back here (while Bruce is still "on holiday"), I still think we need a better naming strategy for the testing subroutines.

pathname_f just doesn't evoke any useful meaning to me. filetest_f does - so maybe that is a reasonable change? Or a name on those lines?

I mean that for the subs that do the perl -dash tests, specifically.

@zmughal

zmughal commented Oct 29, 2025

Copy link
Copy Markdown

I don't have deep knowledge of the code, but I did notice this PR.

Could some of this be done by bringing in Path::Tiny and subclassing it? It is a fairly standard OO wrapper for path handling. Via the ->stat method it calls the module File::stat, which is a core module that provides the ->cando() method to do the equivalent of the -X type tests.

It won't solve the encoding problem, but it may help with the API design.

@xworld21

xworld21 commented Nov 1, 2025

Copy link
Copy Markdown
Contributor Author

pathname_f just doesn't evoke any useful meaning to me. filetest_f does - so maybe that is a reasonable change? Or a name on those lines?

In the meanwhile I changed it to pathname_test_X.

@xworld21

xworld21 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

In the meanwhile, I have implemented some portable wrappers around open, test, etc in
https://github.com/vlmantova/bookml/blob/ec993d4136cc2f24bbd16ddcca861b65ca24bc91/bookml.pm
I propose adding something similar within Util::Pathname.

LaTeXML can actually depend directly on Win32::LongPath (which is now inclueded by default in Strawberry Perl) and simplify the code further, without that klugde with the Win32 module, which works, but only if the filesystem supports short paths.

@xworld21

xworld21 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

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.

4 participants