Search code examples
tizentizen-wearable-sdktizen-native-apptizen-emulatortizen-studio

Tizen cannot write file in native application


I am following this example: https://stackoverflow.com/a/41713258/2330482

However, the file cannot be read back after relaunching the application so I've checked in the Device Manager - the folder is not appearing in /opt/usr/home/owner/apps_rw/org.example.basicui/data/ . I've cdd into the .basicui directory and ls - l gives

sh-3.2$ cd apps_rw                                                             
sh-3.2$ cd org.example.basicui
sh-3.2$ ls -l
ls: cannot access cache: Permission denied
ls: cannot access data: Permission denied
total 8
lrwxrwxrwx 1 app_fw app_fw   60 Sep  2 21:31 author-signature.xml -> /opt/usr/globalapps/org.example.basicui/author-signature.xml
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 bin -> /opt/usr/globalapps/org.example.basicui/bin
d????????? ? ?      ?         ?            ? cache
d????????? ? ?      ?         ?            ? data
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 lib -> /opt/usr/globalapps/org.example.basicui/lib
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 res -> /opt/usr/globalapps/org.example.basicui/res
drwxr-xr-x 3 owner  users  4096 Sep  2 21:31 shared
lrwxrwxrwx 1 app_fw app_fw   58 Sep  2 21:31 tizen-manifest.xml -> /opt/usr/globalapps/org.example.basicui/tizen-manifest.xml
sh-3.2$ whoami
owner

my code is the following:

char* get_write_filepath(char *filename)
{

    char write_filepath[1000] = {0,};
    char *resource_path = app_get_data_path(); // get the application data directory path
    if(resource_path)
    {
        snprintf(write_filepath,1000,"%s%s",resource_path,filename);
        free(resource_path);
    }

    return write_filepath;
}

static char* write_file(const char* filepath, const char* buf)
{

    FILE *fp;
    fp = fopen(filepath,"w");
    fputs(buf,fp);
    fclose(fp);

    dlog_print(DLOG_DEBUG, "AAAMYTAG", "written");

}


void saveExampleFile() {
    dlog_print(DLOG_DEBUG, "AAAMYTAG", "save example file");

            char *filepath;
            filepath=get_write_filepath("d.txt");
            write_file(filepath,"TEST");
}

static void //B Button
    btn_go_cb(void *data, Evas_Object *obj, void *event_info)
    {
        dlog_print(DLOG_INFO, "AAAMYTAG", "GO successful.");

        saveExampleFile();
}

Where am I going wrong? Shouldn't the data folder be permanent? Can this be an emulator bug?


Solution

  • The issue lay in Run configurations (next to the run play button) -> "Enable Update Mode".

    This makes data persist and is disabled by default. Let that sink in. Rather than keeping the data through launches and just uninstall the installed app when you want it removed, Samsung makes it the default to delete the data and makes keeping the data an opt-in. This is by far the most ridiculous OS to work on. Never will I understand the intentions behind this, along with having to use C and C++ instead of a proper high-level language. No wonder there are no apps for Tizen.