getFile: function()

in src/windows/FileProxy.js [873:940]


    getFile: function (win, fail, args) {
        const dirurl = args[0];
        const path = args[1];
        const options = args[2];

        const fs = getFilesystemFromURL(dirurl);
        const dirpath = pathFromURL(dirurl);
        if (!fs || !validName(path)) {
            fail(FileError.ENCODING_ERR);
            return;
        }
        const fspath = sanitize(dirpath + '/' + path);
        const completePath = sanitize(fs.winpath + fspath);

        const fileName = completePath.substring(completePath.lastIndexOf('/') + 1);

        const wpath = cordovaPathToNative(completePath.substring(0, completePath.lastIndexOf('/')));

        let flag = '';
        if (options !== null) {
            flag = new Flags(options.create, options.exclusive);
        } else {
            flag = new Flags(false, false);
        }

        getFolderFromPathAsync(wpath).done(
            function (storageFolder) {
                if (flag.create === true && flag.exclusive === true) {
                    storageFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.failIfExists).done(
                        function (storageFile) {
                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                        }, function () {
                            fail(FileError.PATH_EXISTS_ERR);
                        }
                    );
                } else if (flag.create === true && flag.exclusive === false) {
                    storageFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.openIfExists).done(
                        function (storageFile) {
                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                        }, function () {
                            fail(FileError.INVALID_MODIFICATION_ERR);
                        }
                    );
                } else if (flag.create === false) {
                    storageFolder.getFileAsync(fileName).done(
                        function (storageFile) {
                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                        }, function () {
                            // check if path actually points to a folder
                            storageFolder.getFolderAsync(fileName).done(
                                function () {
                                    fail(FileError.TYPE_MISMATCH_ERR);
                                }, function () {
                                    fail(FileError.NOT_FOUND_ERR);
                                }
                            );
                        }
                    );
                }
            }, function (err) {
                fail(
                    err.number === WinError.accessDenied
                        ? FileError.SECURITY_ERR
                        : FileError.NOT_FOUND_ERR
                );
            }
        );
    },