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

File opened with "open_encrypted_with_pass" and "READ_WRITE" mode failes to store data #64575

Open
Kay-Eth opened this issue Aug 18, 2022 · 2 comments

Comments

@Kay-Eth
Copy link

Kay-Eth commented Aug 18, 2022

Godot version

v3.5.stable.mono.official [991bb6a]

System information

Windows 11

Issue description

When I open a file using open_encrypted_with_pass method with READ_WRITE mode, seek_end of the file (but without it, does not work either) and then try to store_string some text I 'm getting an error:

E 0:00:02.128   store_buffer: File has not been opened in write mode.
  <C++ Error>   Condition "!writing" is true.
  <C++ Source>  core/io/file_access_encrypted.cpp:241 @ store_buffer()
  <Stack Trace> TestScene.gd:24 @ _input()

If I open a file with open method it works as expected.

I experienced this bug when I was trying to troubleshoot someone's problem on Reddit.

Steps to reproduce

Check minimal reproduction project. Just create a scene with Node node and attach this script to it.

Minimal reproduction project

extends Node


func _ready():
	var file = File.new()
	var err = file.open_encrypted_with_pass("user://file.txt", File.WRITE, "tralalalalala")
#	var err = file.open("user://file.txt", File.WRITE)
	if err == OK:
		file.store_line("Test")
		file.close()
	else:
		push_error(err)

func _input(event):
	if event is InputEventKey:
		if event.pressed and event.scancode == KEY_SPACE:
			var file = File.new()
			var err = 0
			
			err = file.open_encrypted_with_pass("user://file.txt", File.READ_WRITE, "tralalalalala")
#			err = file.open("user://file.txt", File.READ_WRITE)
			if err == OK:
				file.seek_end()
				file.store_string("Test" + str(OS.get_time()) + "\n")
				file.close()
			else:
				push_error(err)
			
			err = file.open_encrypted_with_pass("user://file.txt", File.READ, "tralalalalala")
#			err = file.open("user://file.txt", File.READ)
			if err == OK:
				print(file.get_as_text())
				file.close()
			else:
				push_error(err)
@Kay-Eth
Copy link
Author

Kay-Eth commented Aug 18, 2022

I read the documentation more carefully. There is a information, that the open_encrypted_with_pass method "Opens an encrypted file in write or read mode.". So I believe, that opening a file in READ_WRITE mode should not be possible to avoid confusion. Besides, the open method have a similar description: "Opens the file for writing or reading, depending on the flags.". The only difference is the -ing postfix and lack of "mode" word. Maybe the documentation needs an update?

@pytomtoto
Copy link

any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants