Skip to main content
Inspiring
November 1, 2013
Question

File.preventBackup Not Working

  • November 1, 2013
  • 1 reply
  • 1166 views

Hi,

I'm possibly using this property in the wrong manner, but I couldn't find any examples. In the startup of my mobile app, I'm doing something like:

var cacheDir:File = File.applicationStorageDirectory.resolvePath("cache");

cacheDir.preventBackup = true;

However, on iOS this directory is still getting backed up. Throughout the mobile app I am referencing File.applicationStorageDirectory.resolvePath("cache").url to open and write files. Should I instead be referencing the cacheDir variable in order for this to work? I wouldn't think it'd make a difference since both point to the same location.

thx

This topic has been closed for replies.

1 reply

leejkAuthor
Inspiring
November 1, 2013

Since File.applicationStorageDirectory returns a File object reference to the same location, why doesn't my implemenation work? Any suggestions?

I'm using AIR 3.9.1200 beta.

Adobe Employee
November 5, 2013

Setting preventBackup property to true/false immediately sets the file attributes of the file if the file exists on the disk. In case it is created later using the same variable, it is automatically set.

In your case

var cacheDir:File = File.applicationStorageDirectory.resolvePath("cache");

cacheDir.preventBackup = true; // this will set the attribute it cache directory existed in File.applicationStorageDirectory otherwise if cacheDir ir is written to disk later , it is still set.

However if use any third object to create cache directory inside the File.applicationStorageDirectory later, preventBackup would be false by default.

I hope this clears your query.

leejkAuthor
Inspiring
November 5, 2013

Not so much. What seems to be happening is that when I initially set the top level cacheDir preventBackup property to true, it remains true until after the first time I access it again later in the application. Then it's somehow reset to false. It doesn't "stick".

Questions:

When this line of code is read in the main application MXML, this directory is not created yet, correct?

var cacheDir:File = File.applicationStorageDirectory.resolvePath("cache");

cacheDir.preventBackup = true;

So later in another MXML View in the application when I write to this location with a file name like this:

var stream:FileStream = new FileStream();

var destFile:File;

destFile = FlexGlobals.topLevelApplication.cacheDir.resolvePath(_languageId + "/406tree_" + _languageId + "_" + _regionId + ".xml");

destFile.preventBackup = true;

stream.openAsync(destFile, FileMode.WRITE);

stream.writeUTFBytes(_machineProductTreeData.productXmlData.toString());

stream.close();

it seems that it resets the preventBackup property on the cacheDir to false. And even though I'm setting the property to true on each file I write, they still get backed up in iCloud. How this is not working escapes me, unless it's broke.