Android/Linux 文件权限问题
我在应用程序的内部存储 (/data/data/com.my_app) 中创建了一个目录,并通过方法
context.getDir(DATA_DIR_NAME, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE) 授予该目录全局读/写权限;
通过我的应用程序,我验证了 linux 文件权限是否正确:
drw-rw-rw- app_71 app_71 2010-11-16 18:38 app_data
我能够读取/将文件写入/写入目录 app_data 就可以了。然而,我的一位开发人员突然无法再写入该目录。我们的应用程序也无法访问他设备上的目录。
奇怪的是目录的文件权限还是一样。我们无法对该目录进行任何类型的写入,也无法再读取该目录中的任何文件(这些文件之前已被授予全局 rw 权限)。
我们唯一能做的就是 adb shell ls /data/data/my_app/app_data
来查看我们的文件列表。奇怪的是,执行 adb shell ls -l /data/data/my_app/app_data
不会返回任何内容。我们也无法将 CD 放入该目录。
有谁知道问题是什么或如何解决这个问题?我们已经无计可施了。
非常感谢。
I have created a directory in my app's internal storage (/data/data/com.my_app) and gave global read/write permissions to the directory via the method
context.getDir(DATA_DIR_NAME, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
Through my app, I verified that the linux file permissions are correct:
drw-rw-rw- app_71 app_71 2010-11-16 18:38 app_data
And I was able to read/write files in-to/out-of the directory app_data just fine. However, one of my developers suddenly wasn't able to write to the directory anymore. Our application has trouble accessing the directory on his device as well.
The strange thing is that the file permission for the directory is still the same. We can't do any sort of writes to the directory, and we can't read any files within the directory anymore either (the files were given global rw permission previously).
The only thing we can do is adb shell ls /data/data/my_app/app_data
to see our list of files. Doing adb shell ls -l /data/data/my_app/app_data
strangely doesn't return anything. And we can't CD into the directory either.
Does anyone have any pointer on what the problem is or how to solve this? We are at our wit's end.
Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目录需要设置执行 (X) 位才能访问目录的内容。我不知道 Android 模式,但请查找
MODE_WORLD_EXECUTABLE
并看看是否可以设置它。基本上,您需要模式 0777 (rwxrwxrwx) 才能以所有权限全局访问目录。
ls
起作用的原因是您有权读取目录中的文件名。ls -l
不起作用,因为您无法访问目录中的文件来获取-l
将打印的元数据。Directories need to have the execute (X) bit set to be able to access the contents of the directory. I don't know the android modes, but look for
MODE_WORLD_EXECUTABLE
and see if you can set that.Basically, you need mode 0777 (rwxrwxrwx) for a directory to be globally accessed with all permissions.
The reason
ls
works is that you have permission to read the filenames in the directory.ls -l
does not work, because you cannot access the files in the directory to get the metadata that-l
will print.