02-11-2013 01:56 PM
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
Solved! Go to Solution.
02-13-2013 07:51 PM
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
02-16-2013 02:39 PM
02-17-2013 11:19 PM
It looks like this problem might also be related:
- 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),
02-18-2013 12:19 AM
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...
02-18-2013 04:54 AM
Confirmed on my Z10. 193 files in a directory on the SD card and my app can only see 28.
02-18-2013 12:49 PM
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:
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. .
02-18-2013 03:43 PM
02-19-2013 02:46 AM
02-19-2013 10:36 AM
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.