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

Clear storage #376

Merged
merged 9 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios-sdk
Submodule ios-sdk updated 54 files
+8 −8 doc/CONFIGURATION.md
+17 −1 ownCloudSDK.xcodeproj/project.pbxproj
+1 −1 ownCloudSDK.xcodeproj/xcshareddata/xcschemes/Ocean.xcscheme
+1 −1 ownCloudSDK.xcodeproj/xcshareddata/xcschemes/ownCloudSDK.xcscheme
+2 −0 ownCloudSDK/Connection/Capabilities/OCCapabilities.h
+12 −0 ownCloudSDK/Connection/Capabilities/OCCapabilities.m
+8 −1 ownCloudSDK/Connection/OCConnection+Sharing.m
+2 −0 ownCloudSDK/Connection/OCConnection.h
+4 −1 ownCloudSDK/Connection/OCConnection.m
+5 −1 ownCloudSDK/Core/ItemList/OCCore+ItemList.m
+7 −0 ownCloudSDK/Core/OCCore.h
+43 −5 ownCloudSDK/Core/OCCore.m
+9 −0 ownCloudSDK/Core/Sharing/OCCore+Sharing.m
+9 −0 ownCloudSDK/Core/Sync/Actions/CopyMove/OCSyncActionCopyMove.m
+8 −0 ownCloudSDK/Core/Sync/Actions/CreateFolder/OCSyncActionCreateFolder.m
+8 −0 ownCloudSDK/Core/Sync/Actions/Delete/OCSyncActionDelete.m
+2 −0 ownCloudSDK/Core/Sync/Actions/Download/OCSyncActionDownload.h
+12 −0 ownCloudSDK/Core/Sync/Actions/Download/OCSyncActionDownload.m
+19 −5 ownCloudSDK/Core/Sync/Actions/OCSyncAction.h
+52 −0 ownCloudSDK/Core/Sync/Actions/OCSyncAction.m
+9 −0 ownCloudSDK/Core/Sync/Actions/Update/OCSyncActionUpdate.m
+2 −2 ownCloudSDK/Core/Sync/Actions/Upload/OCSyncActionUpload.h
+13 −0 ownCloudSDK/Core/Sync/Actions/Upload/OCSyncActionUpload.m
+244 −65 ownCloudSDK/Core/Sync/OCCore+SyncEngine.m
+37 −0 ownCloudSDK/Core/Sync/Record/OCSyncLane.h
+133 −0 ownCloudSDK/Core/Sync/Record/OCSyncLane.m
+4 −0 ownCloudSDK/Core/Sync/Record/OCSyncRecord.h
+10 −0 ownCloudSDK/Core/Sync/Record/OCSyncRecord.m
+3 −11 ownCloudSDK/Events/NSProgress+OCEvent.h
+3 −3 ownCloudSDK/Events/OCEvent.h
+0 −2 ownCloudSDK/HTTP/Pipeline/OCHTTPPipeline.h
+4 −7 ownCloudSDK/HTTP/Pipeline/OCHTTPPipeline.m
+1 −1 ownCloudSDK/HTTP/Pipeline/OCHTTPPipelineManager.m
+4 −2 ownCloudSDK/HTTP/Request/OCHTTPRequest.m
+2 −1 ownCloudSDK/Item/OCItem.h
+9 −0 ownCloudSDK/Item/OCItem.m
+23 −20 ownCloudSDK/Logging/OCLogger.h
+8 −2 ownCloudSDK/Logging/OCLogger.m
+4 −4 ownCloudSDK/Logging/Writers/OCLogWriter.m
+4 −0 ownCloudSDK/OCTypes.h
+5 −0 ownCloudSDK/Share/OCShare+OCXMLObjectCreation.m
+1 −0 ownCloudSDK/Share/OCShare.h
+30 −1 ownCloudSDK/Share/OCShare.m
+1 −0 ownCloudSDK/Vaults/Database/OCDatabase+Schemas.h
+149 −5 ownCloudSDK/Vaults/Database/OCDatabase+Schemas.m
+17 −2 ownCloudSDK/Vaults/Database/OCDatabase.h
+372 −63 ownCloudSDK/Vaults/Database/OCDatabase.m
+21 −0 ownCloudSDK/Vaults/OCVault+Internal.h
+205 −0 ownCloudSDK/Vaults/OCVault+Internal.m
+4 −1 ownCloudSDK/Vaults/OCVault.h
+14 −8 ownCloudSDK/Vaults/OCVault.m
+1 −1 ownCloudSDKTests/CertificateTests.m
+103 −0 ownCloudSDKTests/CoreSharingTests.m
+73 −1 ownCloudSDKTests/SharingTests.m
4 changes: 4 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
4C6B78102226B83300C5F3DB /* PhotoAlbumTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */; };
4C6B78122226B86300C5F3DB /* PhotoAlbumTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */; };
4C80B1E62271BBB400252901 /* PhotoUploadSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C80B1E52271BBB400252901 /* PhotoUploadSection.swift */; };
4CAF783C2282FD40000C85CF /* FileManager+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */; };
4CF8CAB121F9B70600B8CA67 /* UIBarButtonItem+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8CAB021F9B70500B8CA67 /* UIBarButtonItem+Extension.swift */; };
5917244E20D3DC2100809B38 /* BiometricalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5917244D20D3DC2100809B38 /* BiometricalTests.swift */; };
593A821120C7D4C5000E2A90 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 593A821320C7D4C5000E2A90 /* Localizable.strings */; };
Expand Down Expand Up @@ -512,6 +513,7 @@
4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewController.swift; sourceTree = "<group>"; };
4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewCell.swift; sourceTree = "<group>"; };
4C80B1E52271BBB400252901 /* PhotoUploadSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoUploadSection.swift; sourceTree = "<group>"; };
4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Extension.swift"; sourceTree = "<group>"; };
4CF8CAB021F9B70500B8CA67 /* UIBarButtonItem+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Extension.swift"; sourceTree = "<group>"; };
5917244D20D3DC2100809B38 /* BiometricalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BiometricalTests.swift; sourceTree = "<group>"; };
593A821220C7D4C5000E2A90 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1383,6 +1385,7 @@
23E22BB220C6A5C40024D11E /* UIDevice+UIUserInterfaceIdiom.swift */,
DC85493321831B0B00782BA8 /* Tools.swift */,
DCB44D86218718BA00DAA4CC /* VendorServices.swift */,
4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */,
);
path = Tools;
sourceTree = "<group>";
Expand Down Expand Up @@ -1960,6 +1963,7 @@
DC3BE0DE2077CC14002A0AC0 /* ClientQueryViewController.swift in Sources */,
4C1561EF22232357009C4EF3 /* PhotoSelectionViewCell.swift in Sources */,
23C56538212167BE00BD4B47 /* CardTransitionDelegate.swift in Sources */,
4CAF783C2282FD40000C85CF /* FileManager+Extension.swift in Sources */,
6E3A104D219D6F0100F90C96 /* DuplicateAction.swift in Sources */,
DC1B270A209CF0D3004715E1 /* ConnectionIssueViewController.swift in Sources */,
DC0B37972051681600189B9A /* ThemeButton.swift in Sources */,
Expand Down
69 changes: 69 additions & 0 deletions ownCloud/Bookmarks/BookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class BookmarkViewController: StaticTableViewController {
var showedOAuthInfoHeader : Bool = false
var activeTextField: UITextField?

var storageSection : StaticTableViewSection?
var offlineStorageInfoRow: StaticTableViewRow?
var deviceAvailableStorageInfoRow: StaticTableViewRow?
var deleteLocalFilesRow : StaticTableViewRow?

lazy var continueBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Continue".localized, style: .done, target: self, action: #selector(handleContinue))
lazy var saveBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(BookmarkViewController.userActionSave))
lazy var nextBarButtonItem = UIBarButtonItem(image: UIImage(named: "arrow-down"), style: .plain, target: self, action: #selector(toogleTextField))
Expand Down Expand Up @@ -67,6 +72,12 @@ class BookmarkViewController: StaticTableViewController {

private var mode : BookmarkViewControllerMode

lazy var byteCounterFormatter: ByteCountFormatter = {
let formatter = ByteCountFormatter()
formatter.allowsNonnumericFormatting = false
return formatter
}()

// MARK: - Init & Deinit
init(_ editBookmark: OCBookmark?) {
// Determine mode
Expand Down Expand Up @@ -251,6 +262,40 @@ class BookmarkViewController: StaticTableViewController {
self.urlRow?.cell?.accessoryView = vectorImageView
}

offlineStorageInfoRow = StaticTableViewRow(valueRowWithAction: nil, title: "Offline files use".localized, value: "uknown".localized)
let deviceFreeTitle = String(format: "Free on %@".localized, UIDevice.current.name)
deviceAvailableStorageInfoRow = StaticTableViewRow(valueRowWithAction: nil, title: deviceFreeTitle, value: "uknown".localized)

deleteLocalFilesRow = StaticTableViewRow(buttonWithAction: { [weak self] (_, _) in
if let bookmark = self?.bookmark {

OCCoreManager.shared.scheduleOfflineOperation({ (bookmark, completionHandler) in
let vault : OCVault = OCVault(bookmark: bookmark)

vault.compact(completionHandler: { (_, error) in
OnMainThread {
if error != nil {
// Inform user if vault couldn't be comp acted
let alertController = UIAlertController(title: NSString(format: "Compacting of '%@' failed".localized as NSString, bookmark.shortName as NSString) as String,
message: error?.localizedDescription,
preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: nil))

self?.present(alertController, animated: true, completion: nil)
}

self?.updateStorageInfo()

completionHandler()
}
})
}, for: bookmark)
}
}, title: "Delete Offline Copies".localized, style: .destructive, identifier: "row-offline-copies-delete")

storageSection = StaticTableViewSection(headerTitle: "Storage".localized, footerTitle: nil, identifier: "section-credentials", rows: [ offlineStorageInfoRow!, deviceAvailableStorageInfoRow!, deleteLocalFilesRow! ])

// Update contents
self.composeSectionsAndRows(animated: false)
}
Expand All @@ -263,6 +308,7 @@ class BookmarkViewController: StaticTableViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.updateInputFocus()
updateStorageInfo()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down Expand Up @@ -692,6 +738,12 @@ class BookmarkViewController: StaticTableViewController {
}
}

if storageSection?.attached == false {
if let storageSectionIndex = credentialsSection?.index {
self.insertSection(storageSection!, at: storageSectionIndex+1, animated: animated)
}
}

if showOAuthInfoHeader {
self.tableView.tableHeaderView = oAuthInfoView
self.tableView.layoutTableHeaderView()
Expand Down Expand Up @@ -810,6 +862,23 @@ class BookmarkViewController: StaticTableViewController {
}
}

func updateStorageInfo() {
if bookmark != nil {
if let vaultURL = OCVault(bookmark: bookmark!).filesRootURL {
FileManager.default.calculateDirectorySize(at: vaultURL) { (size) in
if size != nil {
let occupiedSpace = self.byteCounterFormatter.string(fromByteCount: size!)
self.offlineStorageInfoRow?.value = occupiedSpace
}
felix-schwarz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
let deviceFreeByteCount = FileManager.default.availableFreeStorageSpace()
if deviceFreeByteCount >= 0 {
deviceAvailableStorageInfoRow?.value = self.byteCounterFormatter.string(fromByteCount: deviceFreeByteCount)
}
}

// MARK: - Tools
func isBookmarkComplete(bookmark: OCBookmark?) -> Bool {
return (bookmark?.url != nil) && (bookmark?.authenticationMethodIdentifier != nil) && (bookmark?.authenticationData != nil)
Expand Down
6 changes: 6 additions & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,9 @@
/* Photo upload settings */
"Photo Upload" = "Photo Upload";
"Convert HEIC to JPEG" = "Convert HEIC to JPEG";

"Free on %@" = "Free on %@";
"unknown" = "unknown";
"Offline files use" = "Offline files use";
"Compacting of '%@' failed" = "Compacting of '%@' failed";
"Delete Offline Copies" = "Delete Offline Copies";
2 changes: 1 addition & 1 deletion ownCloud/Server List/ServerListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class ServerListTableViewController: UITableViewController, Themeable {
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
self?.showBookmarkUI(edit: bookmark)
}
})
}),
]
}

Expand Down
2 changes: 1 addition & 1 deletion ownCloud/Settings/UserInterfaceSettingsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserInterfaceSettingsSection: SettingsSection {

themeRow = StaticTableViewRow(valueRowWithAction: { [weak self] (_, _) in
self?.pushThemeStyleSelector()
}, title: "Theme".localized, value: ThemeStyle.preferredStyle.localizedName)
}, title: "Theme".localized, value: ThemeStyle.preferredStyle.localizedName, accessoryType: .disclosureIndicator)

self.add(row: themeRow!)

Expand Down
53 changes: 53 additions & 0 deletions ownCloud/Tools/FileManager+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// FileManager+Extension.swift
// ownCloud
//
// Created by Michael Neuwert on 08.05.2019.
// Copyright © 2019 ownCloud GmbH. All rights reserved.
//

/*
* Copyright (C) 2018, ownCloud GmbH.
*
* This code is covered by the GNU Public License Version 3.
*
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import Foundation

extension FileManager {
func calculateDirectorySize(at url:URL, completion:@escaping (_ sizeInBytes:Int64?) -> Void) {
DispatchQueue.global(qos: .background).async {
let enumerator = self.enumerator(at: url, includingPropertiesForKeys: [URLResourceKey.fileSizeKey], options: [.skipsHiddenFiles])

var totalSize:Int64?
if enumerator != nil {
totalSize = 0
for case let fileURL as URL in enumerator! {
if let fileAttrs = try? self.attributesOfItem(atPath: fileURL.path) {
if let size = (fileAttrs[FileAttributeKey.size] as? NSNumber)?.int64Value {
totalSize! += size
}
}
}
}

OnMainThread {
completion(totalSize)
felix-schwarz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

func availableFreeStorageSpace() -> Int64 {
var bytesAvailable: Int64 = -1
if let attributes = try? self.attributesOfFileSystem(forPath: "/") {
if let value = attributes[FileAttributeKey.systemFreeSize] as? NSNumber {
bytesAvailable = value.int64Value
}
}
return bytesAvailable
}
}
8 changes: 7 additions & 1 deletion ownCloud/UI Elements/StaticTableViewRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ class StaticTableViewRow : NSObject, UITextFieldDelegate {
self.cell?.accessibilityIdentifier = identifier

self.action = subtitleRowWithAction

self.updateViewFromValue = { (row) in
if let value = row.value as? String {
row.cell?.detailTextLabel?.text = value
}
}
}

convenience init(valueRowWithAction: StaticTableViewRowAction?, title: String, value: String, accessoryType: UITableViewCell.AccessoryType = UITableViewCell.AccessoryType.none, identifier : String? = nil) {
self.init(subtitleRowWithAction: valueRowWithAction, title: title, subtitle: value, style: .value1, accessoryType: .disclosureIndicator, identifier: identifier)
self.init(subtitleRowWithAction: valueRowWithAction, title: title, subtitle: value, style: .value1, accessoryType: accessoryType, identifier: identifier)
}

// MARK: - Radio Item
Expand Down