Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Testing and Deployment

Reply
Developer
Enaud
Posts: 74
Registered: ‎02-08-2013
My Device: z10
Accepted Solution

Shared subdirectories inaccessible to Cascades based App

Hello All,

 

I've encountered a odd problem I've been stuck on for a while now.

 

Part of my app searches the shared folders for files of a certain type. Several times now after copying whole directories to the documents, downloads, or books directory from windows (via USB card reader, direct USB connect to phone, or target filesystem navigator) my app can see the subdirectory I copied but not the files inside, only the '.' and '..' entries.

 

I thought it was my app to I made another app that simply searches the directories, it behaved in the same manner. If I copy the directory to a new location the files sometimes appear.

 

I have the appropriate permissions set in my bar file and the files are viewable via ssh console and target filesystem navigator.

 

The access_shared permission seems to be inconsistently applied to my cascades App. Has anyone else had a similar experience?

 

Thanks,

Eric

Developer
Enaud
Posts: 74
Registered: ‎02-08-2013
My Device: z10

Re: Shared subdirectories inaccessible to Cascades based App

I'm growing a little more certain that there is something wrong regarding the SDCard storage and application of permissions. Here are some additional findings:

 

1. First I format a brand new SD card in the phone, then insert it into my PC and copy over a series of MP3s folders.

2. I create a new APP in the IDE with something like this running:

FileTest::FileTest(bb::cascades::Application *app)
: QObject(app)
{
	QDir dir;
	dir.setPath("/accounts/1000/");
	scanDir(dir);
}

bool FileTest::scanDir(QDir dir)
{
	if (!dir.exists())
		return false;

   QDirIterator iterator(dir.absolutePath(), QDir::Files | QDir::NoSymLinks | QDir::AllDirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
   while (iterator.hasNext()) {
	  iterator.next();
	  if (!iterator.fileInfo().isDir()) {
		 QString filename = iterator.fileName();
		 QString path     = iterator.filePath();
		 fprintf(stderr, "file: %s\n", path.toStdString().c_str());
	  } else {
		  fprintf(stderr, "dir: %s\n", iterator.filePath().toStdString().c_str());
	  }
   }
   return(true);
}

 3. The first MP3 folder is read and files listed. The second MP3 folder is read but files are not listed. Using plain C code (using opendir and readdir) I see only '.' and '..' entries in the folder whose files aren't listed by the code above. For all intents and purposes the application thinks the folder is empty. The target file system navigator show the files are present and ls via ssh session shows the files. They are there but permissions appear to be lacking in my app regardless of access_shared set in the bar file.

4. Now I copy over the files to the internal phone storage and run the same test: All the files are listed.

 

I've run this test cycle several time using different media, different storage cards and different folder listing code. In each case there are sometimes several folders that are not visible to the application but present from the shell.

 

Am I missing a configuration here? Is this a bug in my code or could permissions actually be playing a role here? Has anyone else had this experience? I suppose the next step is to run this on another unit.

 

Thank you

Eric

Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Device: Z10, PlayBook

Re: Shared subdirectories inaccessible to Cascades based App

That sounds exactly like the problem I've had. Before I finally got a Z10, a friend at RIM tested my app for me. One directory had several files, but opendir and readdir listed only three aside from '.' and '..'. Just received my Z10 on Wednesday and haven't had a chance to run my test app yet, but I bought my app from BlackBerry World and it looks like it has the same problem. Need to verify it with my test app, of course, but my app is getting an incomplete directory listing.

I'm using a new SD card, formatted in the device. previously the permissions all appeared to be the same. I expect that to be the case this time too.
Developer
Enaud
Posts: 74
Registered: ‎02-08-2013
My Device: z10

Re: Shared subdirectories inaccessible to Cascades based App

It looks like this problem might also be related:

http://supportforums.blackberry.com/t5/BlackBerry-Z10/Music-on-Z10-phone-and-SD-card-but-not-found-b...

 

- I've also tested on a second phones, so it's not a phone specific thing.

- I formated using the phone, windows and linux with no discernable difference.

- I copied the files using windows and linux directly to the SD card and via the USB cable with no difference in behaviour.

- The file permissions, owner and owner ID are all the same on the directories read by the app and those not able to be read by the app.

- I've seen my test program be able to read some directories but after making a small modification to the app the directory becomes unreadable.

- The QDir iterator code I posted and this opendir/readdir code product the problem:

bool listdir(const char *name, int level)
{
    DIR *dir;
    struct dirent *entry;
    struct stat st_buf;

    dir = opendir(name);
    if (dir == NULL) {
    	fprintf(stderr, "opendir error %d [%s] for %s\n", errno, strerror(errno), name);
        return false;
    }

    entry = readdir(dir);

    do {
    	if (entry == NULL) {
			if (errno)
				fprintf(stderr, "readdir error %d\n", errno);
		}
    	char filepath[512];
    	memset(filepath, 0x00, 512);

    	if (entry == NULL) {
        	fprintf(stderr, "readdir error %d", errno);
            return false;
    	}

    	strcpy(filepath, name);
    	strcat(filepath, "/");
    	strcat(filepath, entry->d_name);
    	if (stat(filepath, &st_buf) == -1) {
        	fprintf(stderr, "stat error %d on %s", errno, entry->d_name);
            return false;
    	}

        if (S_ISDIR(st_buf.st_mode)) {
            char path[1024];
            int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name);
            path[len] = 0;
            if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
                continue;
            printf("%*s[%s] (%d)\n", level*2, "", entry->d_name);
            listdir(path, level + 1);
        }
        else
        	printf("%*s- %s (%d)\n", level*2, "", entry->d_name);
        errno = 0;
    } while ((entry = readdir(dir)));
    closedir(dir);
    fflush(stderr);
    fflush(stdout);
    return(true);

}

Whatever mechanism that enforces the acess_shared permission, over and beyond the filesystem based  permissions, seems to be inconsistently applied to the SD card filesystem. Incidently, while testing I removed access_shared permission for my app but still managed to access shared folder and files... (via settings->security->app permissions),

 

 

Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Device: Z10, PlayBook

Re: Shared subdirectories inaccessible to Cascades based App

Have you submitted a bug report yet? You've collected better details than me. If I report it, I'd like to reference your report...

Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Device: Z10, PlayBook

Re: Shared subdirectories inaccessible to Cascades based App

Confirmed on my Z10. 193 files in a directory on the SD card and my app can only see 28.

Developer
Enaud
Posts: 74
Registered: ‎02-08-2013
My Device: z10

Re: Shared subdirectories inaccessible to Cascades based App

I wish I could submit a bug. The only link I found to do so is this one, and It doesn't seem to work:

https://www.blackberry.com/jira

 

It send my Chrome, Firefox, Explorer, and playbook browser into an unending loop after I login. This problem also appears to be experienced by others based on this dicussion:

http://supportforums.blackberry.com/t5/Adobe-AIR-Development/Found-a-bug-Report-it-using-the-Develop...

 

Can a moderator comment how move forward with this problem and if Jira is just temporarily down?  

 

If this is indeed a problem with the Z10's SDcard storage or permissions (and not my code, which is still a possibility  I suppose) I would hope there was more interest in this. This kind of problem would/will affect any future podcast, music/image browser, and ebook reader type apps, basically any App that depends on files/media on the sd card won't be able to find the files they support, and the user will be left mystified as I am. .

Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Device: Z10, PlayBook

Re: Shared subdirectories inaccessible to Cascades based App

Looks to me like it's temporarily down. I just clicked on that jira link you gave and it took me to the issue tracker. I'd already logged in via developer.blackberry.com, but that just gave me a page saying the system was undergoing site maintenance.

"Site Map: Maintenance

Our website is currently undergoing a scheduled maintenance to upgrade our systems in order to better serve you.

We apologize for any inconvenience and thank you for your patience."
Developer
torpesco
Posts: 121
Registered: ‎01-29-2011
My Device: Z10, PlayBook

Re: Shared subdirectories inaccessible to Cascades based App

BTW... what size of SD card are you using? I've got a 64GB card. Don't recall what size my friend was using.
Developer
Enaud
Posts: 74
Registered: ‎02-08-2013
My Device: z10

Re: Shared subdirectories inaccessible to Cascades based App

I've used a 16GB and 4GB, righ out of the box. They are all SDHC, if I can find a 2GB card I'll give it a try.