vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

Create Directory #86

Open PizzaPablo666 opened 4 years ago

PizzaPablo666 commented 4 years ago

I need a function to create directory, and did not find anything by showdef Platform. For now I am using this module.

MODULE fs;
IMPORT SYSTEM;

PROCEDURE -Aincludesysstat '#include <sys/stat.h>';
PROCEDURE -Aincludesystypes '#include <sys/types.h>';

PROCEDURE -mkdir(VAR path: ARRAY OF CHAR): INTEGER
  "(int)mkdir(path, 0755)";

PROCEDURE mkDir*(VAR path: ARRAY OF CHAR): BOOLEAN;
VAR res: INTEGER;
BEGIN
   res := mkdir(path);
   IF res = 0 THEN RETURN TRUE ELSE RETURN FALSE END
END mkDir;

END fs.

Is it possible to have mkdir implemented in Platform? I am using Linux/Gentoo.

norayr commented 4 years ago

@dcwbrown i can do somithing like that for unix, but how does mkdir work for windows? we need to keep Platformunix.Mod and Platformwindows.Mod synced.

dcwbrown commented 4 years ago

It's called 'CreateDirectory' on Windows. But my hunch is that we don't want to start down the path of providing a general system API in Platform beyond what is needed for Vishap itself.

Windows and Linux do have a great deal in common with regard to filesystem concepts, but there are also some really annoying gotchas such as case sensitivity and which characters are valid in filenames.

Here's a little detail for example: where Linux has a single current directory, Windows has multiple drives and keeps a separate current directory for each drive, as well as a current drive.

Also bear in mind that Vishap Oberon file handling, such as in Files.Mod, is designed to mimic the Oberon system and is somewhat different to the Linux/Windows way of doing things. See https://github.com/vishaps/voc/blob/master/doc/Files.md.

I suggest that it if we were to add functionality to Platform beyond what is needed for Vishap itself, then it would not make sense to single out mkdir as the only system function to add.

It would also seem necessary to add APIs for accessing file attributes, file security, manipulating the current directory, walking directories, dealing with symbolic links, handling mount points, etc..

And so if we do we are committing to a lot of work, and to coming up with a consistant behaviour that works the same across linux and windows and yet does not hide linux and windows specific functionality.

While I have been able to do so with Vishap's needs as the known customer, I don't believe this is possible in the general case.

I think @PizzaPablo666's implementation is a great way to go. It isn't complicated, and it leaves everything under @PizzaPablo666's control.

Any user of Vishap is free to use this approach to access those parts of OS functionality that their particular situation needs.

All the best -- Dave

svorkoetter commented 4 years ago

It would probably make the most sense to create a separate platform-portable FileSystems module that abstracts away the differences.

Stefan

-- Stefan Vorkoetter Senior Architect Maplesoft

antranigv commented 4 months ago

This has been open for a long time now, we need to merge the basics into the Platform or Files.

There are some minor differences between Unix systems, and if we want to expose the stat info to the user, we'd need to implement it for Linux, FreeBSD, OpenBSD, NetBSD, AIX, illumos, etc.

@norayr any thoughts?

dcwbrown commented 4 months ago

I stand by my earlier analysis. to simplify: a platform-portable filesystem is a nice aspiration but not a practical goal.

antranigv commented 4 months ago

After spending couple of hours thinking about this, I agree. We should create a module named Filesystem, which has functions such as New, Rename, ChangeOwner, ChangeMod, etc.

I will add a separate module for this, and work on it overtime for the next voc version, keeping Platform as is.

@norayr thoughts?

norayr commented 4 months ago

since

i think it's better to just have it in your github, and add it to our ports system.

i myself think of removing ooc or ulm set of libraries to different repositories. vipack is easy to use to add dependencies to the project. just one json file, and one command to build.