Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-12901: Android: Ti.FileSystemProxy interprets resourceDir as a File #4032

Merged
merged 1 commit into from
Mar 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,36 @@ public class TiResourceFile extends TiBaseFile
private static final String TAG = "TiResourceFile";

private final String path;
private boolean typeFetched = false;

public TiResourceFile(String path)
{
super(TYPE_RESOURCE);
this.path = path;
}

@Override
public boolean isDirectory()
{
if (typeFetched) {
return this.typeDir;
}

fetchType();
return this.typeDir;
}

@Override
public boolean isFile()
{
if (typeFetched) {
return this.typeFile;
}

fetchType();
return this.typeFile;
}

@Override
public TiBaseFile resolve()
{
Expand Down Expand Up @@ -243,4 +266,27 @@ public String toString ()
{
return toURL();
}

private void fetchType ()
{
InputStream is = null;
try {
is = getInputStream();
this.typeDir = false;
this.typeFile = true;
} catch (IOException e) {
// getInputStream() will throw a FileNotFoundException if it is a directory or it does not exist.
this.typeDir = true;
this.typeFile = false;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
typeFetched = true;
}
}