存储大于系统

storage greater than system

我想模拟存储空间不足,所以我尝试复制文件直到存储空间已满,但我发现它永远不会到那个位置,而且我发现占用的存储空间大于系统,这怎么可能发生? 代码如下:

+ (void)copeFiles
{
    NSString *srcPath = [self cloudStorageCacheFolderPath];
    NSLog(@"copy: src path:%@ ,size:%f", srcPath, [self sizeOfcloudStorageCacheFolder]);
    int base = 300;
    int i = base;
    while (1) {
        i++;
        if (i > base + 100) {
            break;
        }
        NSInteger freeSizeM = [self freeFileStorageSize];
        if (freeSizeM > 1024) {
            NSString *newFilePath = [NSString stringWithFormat:@"%@-%d", srcPath, i];
            [self copyFolderContentFromSrc:srcPath toDestPath:newFilePath];
            NSLog(@"copy: i:%d, freeSizeM:%li", i, (long)freeSizeM);
        }else {
            break;
        }
    }
}
+ (void)copyFolderContentFromSrc:(NSString *)srcPath toDestPath:(NSString *)dstPath
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSLog(@"copy: src:%@ dst:%@", srcPath, dstPath);
    BOOL isDir;
    if (![fileManager fileExistsAtPath:dstPath isDirectory:&isDir] || !isDir) {
        BOOL sucess = [fileManager createDirectoryAtPath:dstPath withIntermediateDirectories:YES attributes:nil error:nil];
        NSLog(@"copy: isDir:%d sucess:%d", isDir, sucess);
    }
    NSArray* array = [fileManager contentsOfDirectoryAtPath:srcPath error:nil];
    int i = 0;
    for (NSString *fileName in array) {
        i++;
        NSString *srcFullPath = [srcPath stringByAppendingPathComponent:fileName];
        NSString *toFullPath = [dstPath stringByAppendingPathComponent:fileName];
        NSError *error;
        BOOL isSucess = [fileManager copyItemAtPath:srcFullPath toPath:toFullPath error:&error];
        NSLog(@"copy:%d", i);
        if (!isSucess) {
            NSLog(@"copy:error:%@", error);
        }
    }
}

image1 image2 图像可能看不到,所以我简单描述了现象 advance.My iphone 总共是32GB,但是设置中显示可用存储空间是93GB。

是的,如果你再运行它也会增加:)

其背后的原因是它将仅存储引用而不是实际文件。我在我的 mac 系统中做了同样的事情来填充模拟器的 space,我最终得到了相同的 256GB 系统,显示了 4.3 TB 的 space

  • 在设备中,您可以使用录制视频来填充 space,但您仍然不会收到该错误,因为 Apple 会以这种方式管理它。

1) 删除All App目录下的所有临时文件。

2) 然后清除缓存。

Apple 会很好地管理存储space,但仍有一些谜团。