Can't manage to filesystem.write nor filesystem.createDirectory

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
svalorzen
Prole
Posts: 22
Joined: Tue Sep 27, 2022 8:25 am

Can't manage to filesystem.write nor filesystem.createDirectory

Post by svalorzen »

I apologize for opening this thread but I'm getting desperate. I can't seem to make LOVE write files nor create directories in the save folder; I always get the error "Could not set write directory.".

I am setting the identity as the first line of my main.lua:

Code: Select all

function love.load()
    love.filesystem.setIdentity('Test', true)
Reading and listing directories works perfectly. I've scoured a tons of posts about this, and some mentioned that this could be a permission issue (I am on Linux). However, I (1) have verified that the permissions on the save folders are OK, and (2) I can easily write in them by opening a file with `io.open` and writing to that; which should rule out a permission issue as it is literally the same process running. At the same time, if I run love with `sudo` the filesystem write succeeds (although obviously it writes to the save directory of root), which is driving me mad.

I have tried running LOVE as `love .`, and also `love Test/` from outside the folder. I have tried to manually create the save directory (it is not being automatically generated as well.. the root one did though).

Is there anything else I can do to diagnose the problem? Any way to obtain some more detailed error message from LOVE?

This is my current full test case:

Code: Select all

function love.load()
    love.filesystem.setIdentity('Test', true)
    print(love.filesystem.getIdentity(), love.filesystem.getSaveDirectory()) -- OK
    local r, m = love.filesystem.write("/abc", "abc")                        -- Fails miserably
    print("write result", r, m)
    local files = love.filesystem.getDirectoryItems('/')                     -- Works correctly
    for _, f in ipairs(files) do
        print(f)
    end
    love.event.quit()
end
which outputs:

Code: Select all

$ love Test/
Test	/home/svalorzen/.local/share/love/Test
write result	nil	Could not set write directory.
file_in_main_directory
file_in_save_directory
folder_in_main_directory
folder_in_save_directory
main.lua
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by Bobble68 »

I ran this code on my Windows computer, seems to be working fine, creating a file in my roaming folder. I'm not too familiar with Linux, but I think this is probably a permissions issue.

This probably won't work, but try changing

Code: Select all

local r, m = love.filesystem.write("/abc", "abc")
to

Code: Select all

local r, m = love.filesystem.write("\\abc", "abc")
It's worth a shot, since I heard that windows is ok with /, but other systems prefer \
Dragon
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by Andlac028 »

Bobble68 wrote: Sun Dec 11, 2022 2:06 pm windows is ok with /, but other systems prefer \
No, Linux and OS X uses / as path separator, only Windows uses \, but it usually also allows /.

EDIT: I tested your code above in Ubuntu 22.04 LTS and it worked fine, file abc is created without problems. How you installed love (appimage / pre-compiled binary / from distribution package manager / ... ? Try removing the first slash (try use abc instead of /abc).
svalorzen
Prole
Posts: 22
Joined: Tue Sep 27, 2022 8:25 am

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by svalorzen »

I usually use LOVE as packaged from Ubuntu 20.04, but I have also just tried using the AppImage to run my test and I get the same problem.

The slash I actually added as I was trying things, it seems to not really matter unfortunately.
svalorzen
Prole
Posts: 22
Joined: Tue Sep 27, 2022 8:25 am

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by svalorzen »

I have started to look into this using `strace`, I haven't used it often so it will probably take a bit to parse the entire output.

What I can say for now is that in the log there is no trace of the "abc" file, so LOVE is not even trying to actually write it. On the other hand, it seems it did try to check whether the save folder existed:

Code: Select all

stat("/home/svalorzen/.local/share/love/Test", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
access("/home/svalorzen/.local/share/love/Test", W_OK) = 0
stat("/home/svalorzen/.local/share/love/Test", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
access("/home/svalorzen/.local/share/love/Test", W_OK) = 0
And those calls succeed and return 0 with "W_OK" as parameter, which I think should mean we have write permission to it.
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by BrotSagtMist »

Thing is that stock ubuntu using its stock Löve seems to work. (I am on 18.04 so i cant 100% assure that tho)
So whatever is happening is something specific to your system.
And permissions is the most logical explanation, especially when using sudo they are easy to mess up.
Maybe just delete the löve folder?
obey
svalorzen
Prole
Posts: 22
Joined: Tue Sep 27, 2022 8:25 am

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by svalorzen »

I can definitely believe that it's a problem on my system, but I have no idea what it is, and I would still like to fix it. :( Which love folder do you want me to delete? I have tried the one in `.local/share`, but that doesn't really change anything.
svalorzen
Prole
Posts: 22
Joined: Tue Sep 27, 2022 8:25 am

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by svalorzen »

Ok, so I'm going deep into this. I have cloned LOVE 11.4, compiled it, and I'm now running to try to figure out exactly where that fails. The failing point seems to be (as it should be obvious) in the setup of the write directory. There is a function that is called to create the save directory:

Code: Select all

bool Filesystem::createDirectory(const char *dir)
{
	if (!PHYSFS_isInit())
		return false;

	if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
		return false;

	if (!PHYSFS_mkdir(dir))
		return false;

	return true;
}
The part that fails is the last one, which I guess is the creation of the actual directory. I'll try to look into the PHYSFS library to figure out when that can fail, and if I can put some debugging prints into that.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by Bobble68 »

Andlac028 wrote: Sun Dec 11, 2022 2:47 pm
Bobble68 wrote: Sun Dec 11, 2022 2:06 pm windows is ok with /, but other systems prefer \
No, Linux and OS X uses / as path separator, only Windows uses \, but it usually also allows /.

Ah good to know, I wasn't sure.
Dragon
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Can't manage to filesystem.write nor filesystem.createDirectory

Post by BrotSagtMist »

Okey permissions is ruled out for sure, quality debugging here.
Say do you have some non standard partitioning? Ive had problems in the past on a system that outsourced /home on a separate partition. Just a shot in the dark tho.
Physfs should be stable enough to not bump into weird bugs without a decent explanation i imagine.
obey
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests