2016-08-30 21:44:58 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2016-10-03 15:58:49 +03:00
|
|
|
class Token: Equatable {}
|
|
|
|
|
|
|
|
func == (left: Token, right: Token) -> Bool {
|
|
|
|
return left === right
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:45:52 +03:00
|
|
|
func ==(left: FileItem, right: FileItem) -> Bool {
|
|
|
|
return left.url == right.url
|
|
|
|
}
|
|
|
|
|
|
|
|
class FileItem : CustomStringConvertible, Hashable {
|
2016-08-30 21:44:58 +03:00
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
let url: URL
|
2016-08-30 21:44:58 +03:00
|
|
|
let dir: Bool
|
|
|
|
let hidden: Bool
|
2016-09-11 15:37:04 +03:00
|
|
|
let package: Bool
|
2016-08-30 21:44:58 +03:00
|
|
|
|
2016-10-05 22:45:52 +03:00
|
|
|
var hashValue: Int {
|
|
|
|
return url.hashValue
|
|
|
|
}
|
|
|
|
|
2016-08-30 21:44:58 +03:00
|
|
|
/// When nil, then it has never been fnmatch'ed.
|
|
|
|
weak var ignoreToken: Token?
|
|
|
|
var ignore = false
|
|
|
|
|
|
|
|
var needsScanChildren = false
|
|
|
|
var childrenScanned = false
|
|
|
|
|
|
|
|
var children: [FileItem] = []
|
|
|
|
|
|
|
|
var description: String {
|
2016-10-04 01:23:54 +03:00
|
|
|
return "<FileItem: \(self.url), dir=\(self.dir), hidden=\(self.hidden), package=\(self.package), "
|
2016-08-30 21:44:58 +03:00
|
|
|
+ "needsScan=\(self.needsScanChildren), childrenScanned=\(self.childrenScanned), "
|
|
|
|
+ "ignore=\(self.ignore), ignoreToken=\(self.ignoreToken), "
|
|
|
|
+ "children=\(self.children.count)>"
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
init(_ url: URL) {
|
2016-08-30 21:44:58 +03:00
|
|
|
self.url = url
|
|
|
|
self.dir = url.dir
|
|
|
|
self.hidden = url.hidden
|
2016-09-11 15:37:04 +03:00
|
|
|
self.package = url.package
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|
2016-09-07 21:12:18 +03:00
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func removeChild(withUrl url: URL) {
|
|
|
|
guard let idx = self.children.index(where: { $0.url == url }) else {
|
2016-09-07 21:12:18 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
self.children.remove(at: idx)
|
2016-09-07 21:12:18 +03:00
|
|
|
}
|
2016-08-30 21:44:58 +03:00
|
|
|
}
|