Ejemplo n.º 1
0
        /// <summary>
        /// Checks if we have to recreate rootDirectory.
        /// This is needed because old versions of this storage created too
        /// much different files in the same dir, and Samsung's RFS has a bug
        /// that after the 13.000th creation fails. So if cache is not already
        /// in expected version let's destroy everything (if not in expected
        /// version... there's nothing to reuse here anyway).
        /// </summary>
        private void RecreateDirectoryIfVersionChanges()
        {
            bool recreateBase = false;

            if (!_rootDirectory.Exists)
            {
                recreateBase = true;
            }
            else if (!_versionDirectory.Exists)
            {
                recreateBase = true;
                FileTree.DeleteRecursively(_rootDirectory);
            }

            if (recreateBase)
            {
                try
                {
                    FileUtils.Mkdirs(_versionDirectory);
                }
                catch (CreateDirectoryException)
                {
                    // Not the end of the world, when saving files we will try to
                    // create missing parent dirs
                    _cacheErrorLogger.LogError(
                        CacheErrorCategory.WRITE_CREATE_DIR,
                        typeof(DefaultDiskStorage),
                        "version directory could not be created: " + _versionDirectory);
                }
            }
        }
Ejemplo n.º 2
0
 internal void DeleteOldStorageIfNecessary()
 {
     if (_currentState.DiskStorageDelegate != null && _currentState.RootDirectory != null)
     {
         // LATER: Actually delegate this call to the storage. We shouldn't be
         // making an end-run around it
         FileTree.DeleteRecursively(_currentState.RootDirectory);
     }
 }
        public void TestCreateRootDirectoryIfNecessary()
        {
            DynamicDefaultDiskStorage supplier = CreateInternalCacheDirStorage();

            Assert.IsNull(supplier._currentState.DiskStorageDelegate);
            DirectoryInfo cacheDir = new DirectoryInfo(ApplicationData.Current.LocalCacheFolder.Path);
            DirectoryInfo baseDir  = new DirectoryInfo(Path.Combine(cacheDir.FullName, _baseDirectoryName));

            // Directory is clean
            supplier.CreateRootDirectoryIfNecessary(baseDir);
            baseDir.Refresh();
            Assert.IsTrue(baseDir.Exists);

            // Cleanup
            FileTree.DeleteRecursively(baseDir);

            // A file with the same name exists - this should clobber the file, and create a directory
            // instead
            FileInfo dummyFile = new FileInfo(Path.Combine(cacheDir.FullName, _baseDirectoryName));

            Assert.IsTrue(dummyFile.CreateEmpty());
            Assert.IsTrue(dummyFile.Exists);
            supplier.CreateRootDirectoryIfNecessary(baseDir);
            baseDir.Refresh();
            Assert.IsTrue(baseDir.Exists);

            // Cleanup
            FileTree.DeleteRecursively(baseDir);

            // A directory with the same name exists - and with a file in it.
            // Everything should stay the same
            baseDir.Create();
            FileInfo dummyFile2 = new FileInfo(Path.Combine(baseDir.FullName, "dummy1"));

            Assert.IsTrue(dummyFile2.CreateEmpty());
            Assert.IsTrue(dummyFile2.Exists);
            supplier.CreateRootDirectoryIfNecessary(baseDir);
            baseDir.Refresh();
            dummyFile2.Refresh();
            Assert.IsTrue(dummyFile2.Exists);
        }