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

Berry: Bugfix accessing zip paths with no characters after the hash, add openNextFile to proxy #18894

Merged
merged 1 commit into from
Jun 18, 2023

Conversation

btsimonh
Copy link
Contributor

Description:

Found and resolved a bug where
print(path.listdir('Antiburn.tapp#'))
or event print(path.exist('Antiburn.tapp#'))
would crash TAS because there was no filename to look for in the zip?

Add passthrough of openNextFile, so that folders can be opened and read via the ZipFS proxied filesystems.
This is only when ZipFile has passed back a proxy to a real file (folder).

Heavily tested with this:

import path

def testfs(root)
    print('***** Test root ['..root..']')

    var res = path.exists(root..'pathtest')
    if res == nil
        print('path.exists returned nil')
    end

    if res == true
        res = path.rmdir(root..'pathtest')
        if res != true
            print('path.rmdir did not return true')
        end
    end

    res = path.exists(root..'pathtest')
    if res != false
        print('path.exists did not return false')
    end

    res = path.exists()

    if res != false
        print('path.exists() did not return false')
    end

    res = path.mkdir(root..'pathtest')
    if res != true
        print('path.mkdir did not return true')
    end

    res = path.exists(root..'pathtest')
    if res != true
        print('path.exists did not return true')
    end

    res = path.rmdir(root..'pathtest')
    if res != true
        print('path.rmdir did not return true')
    end

    res = path.listdir(root..'pathtest')
    print('path.listdir of invalid folder gives')
    print(res)

    res = path.mkdir(root..'pathtest')
    if res != true
        print('path.mkdir did not return true')
    end

    res = path.listdir(root..'pathtest')
    print('path.listdir of empty folder gives')
    print(res)

    res = path.mkdir(root..'pathtest/test1')
    res = path.listdir(root..'pathtest')
    print('path.listdir should give "[test1]"')
    print(res)

    var f = open(root..'pathtest/text.txt', 'w');
    f.write('test');
    f.close();
    res = path.listdir(root..'pathtest')
    print('path.listdir should give "[test1, test.txt]"')
    print(res)

    # comment out if not an isdir version of tas
    #res = path.isdir(root..'pathtest/text.txt')
    #if res != false
    #    print('path.isdir did not return false')
    #end

    #res = path.isdir(root..'pathtest/test1')
    #if res != true
    #    print('path.isdir did not return true')
    #end

    res = path.last_modified(root..'pathtest/text.txt')
    print('path.last_modified on file '..res)
    res = path.last_modified(root..'pathtest/test1')
    print('path.last_modified on folder '..res)
    res = path.last_modified(root..'pathtest/test2')
    print('path.last_modified on missing '..res)

    res = path.remove(root..'pathtest/test2') #expect false
    if res != false
        print('path.remove on missing returned '..res)
    end

    res = path.exists(root..'pathtest/text.txt')
    if res != true
        print('path.exists on file did not return true')
    end

    res = path.remove(root..'pathtest/text.txt') #expect true
    if res != true
        print('path.remove on missing returned '..res)
    end

    # 'remove' of folder
    res = path.remove(root..'pathtest/test1') #expect false?
    if res != false
        print('path.remove on folder returned '..res)
    end

    # 'rmdir' of folder
    res = path.rmdir(root..'pathtest/test1') #expect true
    if res != true
        print('path.rmdir on folder returned '..res)
    end
    res = path.rmdir(root..'pathtest/test1') #expect false
    if res != false
        print('path.rmdir on missing folder returned '..res)
    end

    res = path.mkdir(root..'a/b/c')
    if res != false
        print('path.mkdir inside missing did not return false')
    end
end

# test without prefix
testfs('');
# test with / prefix
testfs('/');
# test in a subfolder
var res = path.mkdir('/a')
testfs('/a/');

if path.exists('Antiburn.tapp')
    print('check no crash')
    print(path.listdir('Antiburn.tapp#'))
    print(path.listdir('Antiburn.tapp#test'))
    print(path.listdir('Antiburn.tapp#autoexec.be'))
    print(path.exists('Antiburn.tapp#autoexec.be'))
    var f = open('Antiburn.tapp#autoexec.be', 'r')
    var content = f.read()
    f.close()
    print(size(content))
    content = nil
end

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.10
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

Add passthrough of openNextFile, so that folders can be opened and read via the ZipFS proxied filesystems.
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.

2 participants