Panakotta00 / FicsIt-Networks

Control, Monitor, Manage and Automate your Satisfactory.
https://ficsit.app/mod/FicsItNetworks
GNU General Public License v3.0
155 stars 50 forks source link

Filesystem write fails during autosave, corrupts disk file #260

Open MatthaeusHarris opened 1 year ago

MatthaeusHarris commented 1 year ago

Describe the bug When a computer is writing to a file during an autosave, the write will generate a Lua exception bad argument #2 to 'write' (string expected, got light userdata)

To Reproduce Steps to reproduce the behavior:

  1. Build a computer with a CPU, single stick of memory, and a populated hard drive
  2. Set your autosave interval to 5 minutes
  3. Run the following code:
    
    fs = filesystem
    if fs.initFileSystem("/dev") == false then
    computer.panic("Could not initialize /dev")
    end

drives = fs.childs("/dev")

for idx, drive in pairs(fs.childs("/dev")) do if drive == "serial" then table.remove(drives, idx) end end

for i = 1, #drives do print(drives[i]) end

fs.mount("/dev/" .. drives[1], "/")

handle = fs.open("/test.txt", "w") errorHandle = fs.open("/error_timestamps.txt", "w")

function getTime() timestamp, dateTime, ISOTime = computer.magicTime() return dateTime end

function logTime() handle:write(getTime() .. "\n") end

while true do status, err = pcall(logTime) if not status then local errString = string.format("%s: %s", getTime(), err) print(errString) end event.pull(1) end


4.  When the autosave happens, a write should generate the error.  The test.txt file will be overwritten with about 1kb of 0x00 bytes.

**Expected behavior**
I expect autosaves to not impact filesystem writes other than a short delay.
I expect filesystem writes to write only the data provided in the function call and not corrupt the open file.

**Additional context**
Using Jenkins build 12.