Skip to content

Commit

Permalink
implement missing
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Mar 22, 2016
1 parent e6a6997 commit 599a0c3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 76 deletions.
3 changes: 1 addition & 2 deletions Sources/Vapor/Core/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ public class Application {
// Check in file system
let filePath = self.dynamicType.workDir + "Public" + request.path

var isDir = false
guard FileManager.fileExistsAtPath(filePath, isDirectory: &isDir) else {
guard FileManager.fileAtPath(filePath).exists else {
return nil
}

Expand Down
42 changes: 7 additions & 35 deletions Sources/Vapor/Fixes/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class FileManager {
return Array(buffer)
}

#if swift(>=3.0)
static func fileExistsAtPath(path: String, isDirectory: inout Bool) -> Bool {
var s = stat()
static func fileAtPath(path: String) -> (exists: Bool, isDirectory: Bool) {
var isDirectory = false
var s = stat()
if lstat(path, &s) >= 0 {
if (s.st_mode & S_IFMT) == S_IFLNK {
if stat(path, &s) >= 0 {
isDirectory = (s.st_mode & S_IFMT) == S_IFDIR
} else {
return false
return (false, isDirectory)
}
} else {
isDirectory = (s.st_mode & S_IFMT) == S_IFDIR
Expand All @@ -71,42 +71,14 @@ class FileManager {
// which is a symlink to /private/Net/foo which is not yet mounted...
if (s.st_mode & S_IFMT) == S_IFLNK {
if (s.st_mode & S_ISVTX) == S_ISVTX {
return true
return (true, isDirectory)
}
// chase the link; too bad if it is a slink to /Net/foo
stat(path, &s) >= 0
}
} else {
return false
return (false, isDirectory)
}
return true
}
#else
static func fileExistsAtPath(path: String, inout isDirectory: Bool) -> Bool {var s = stat()
if lstat(path, &s) >= 0 {
if (s.st_mode & S_IFMT) == S_IFLNK {
if stat(path, &s) >= 0 {
isDirectory = (s.st_mode & S_IFMT) == S_IFDIR
} else {
return false
}
} else {
isDirectory = (s.st_mode & S_IFMT) == S_IFDIR
}

// don't chase the link for this magic case -- we might be /Net/foo
// which is a symlink to /private/Net/foo which is not yet mounted...
if (s.st_mode & S_IFMT) == S_IFLNK {
if (s.st_mode & S_ISVTX) == S_ISVTX {
return true
}
// chase the link; too bad if it is a slink to /Net/foo
stat(path, &s) >= 0
}
} else {
return false
}
return true
return (true, isDirectory)
}
#endif
}
26 changes: 8 additions & 18 deletions Sources/Vapor/Fixes/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,15 @@ import libc
}
return true
}

public func componentsSeparatedByString( sep: String ) -> [String] {
var out = [String]()
withCString { (bytes) in
sep.withCString { (sbytes) in
var bytes = UnsafeMutablePointer<Int8>( bytes )
while true {
let start = strstr( bytes, sbytes ) - UnsafeMutablePointer<Int8>( bytes )
if start < 0 {
out.append( String.fromCString( bytes )! )
break
}
bytes[start] = 0
out.append( String.fromCString( bytes )! )
bytes += start + Int(strlen( sbytes ))
}
}

func hasSuffix(str: String) -> Bool {
let strGen = str.characters.reverse().generate()
let selfGen = self.characters.reverse().generate()
let seq = Zip2Sequence(strGen, selfGen)
for (lhs, rhs) in seq where lhs != rhs {
return false
}
return out
return true
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions Sources/Vapor/Hash/CryptoSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class SHA2 {
return ArraySlice(hh)
}


//FIXME: I can't do Generic func out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
func calculate32() -> [UInt8] {
var tmpMessage = self.prepare(64)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Request/RequestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ extension String: Node {

public var array: [Node]? {
return self
.componentsSeparatedByString(",")
.split(",")
.map { $0 as Node }
}

Expand Down
5 changes: 1 addition & 4 deletions Sources/Vapor/Router/Branch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ internal final class Branch {
if let next = subBranches[key] {
return next.handle(request, comps: comps)
} else if let wildcard = subBranches["*"] {
//FIXME
#if swift(>=3.0)
request.parameters[wildcard.name] = key.stringByRemovingPercentEncoding
#endif
request.parameters[wildcard.name] = key.removePercentEncoding()
return wildcard.handle(request, comps: comps)
} else {
return nil
Expand Down
17 changes: 6 additions & 11 deletions Sources/Vapor/Routing/Application+Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ extension Application {
public final func resource<ResourceControllerType: ResourceController>(path: String, makeControllerWith controllerFactory: () -> ResourceControllerType) {
let last = "/:id"

//FIXME
#if swift(>=3.0)
let shortPath = path.componentsSeparatedByString(".")
.flatMap { component in
return [component, "/:\(component)_id/"]
}
.dropLast()
.joinWithSeparator("")
#else
let shortPath = ""
#endif
let shortPath = path.split(".")
.flatMap { component in
return [component, "/:\(component)_id/"]
}
.dropLast()
.joinWithSeparator("")

let fullPath = shortPath + last

Expand Down
3 changes: 0 additions & 3 deletions Sources/Vapor/View/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ public class View {
self.bytes = fileBody

for (suffix, renderer) in View.renderers {
//FIXME
#if swift(>=3.0)
if path.hasSuffix(suffix) {
let template = String.fromUInt8(self.bytes)
let rendered = try renderer.render(template: template, context: context)
self.bytes = [UInt8](rendered.utf8)
}
#endif
}

}
Expand Down

0 comments on commit 599a0c3

Please sign in to comment.