Skip to content

Commit

Permalink
A new fix for issue #181
Browse files Browse the repository at this point in the history
  • Loading branch information
laurilehmijoki committed Sep 18, 2015
1 parent bfd26af commit 8398a92
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project uses [Semantic Versioning](http://semver.org).

## 2.11.2

* A new fix based on
<https://github.com/laurilehmijoki/s3_website/issues/181#issuecomment-141397992>

## 2.11.1

* Prevent runaway recursion in file listing
Expand Down
2 changes: 1 addition & 1 deletion lib/s3_website/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module S3Website
VERSION = '2.11.1'
VERSION = '2.11.2'
end
2 changes: 1 addition & 1 deletion src/main/scala/s3/website/model/Site.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object Site {
| site: dist/website""".stripMargin

def resolveSiteDir(implicit yamlConfig: S3_website_yml, config: Config, cliArgs: CliArgs, workingDirectory: File): Either[ErrorReport, File] = {
val siteFromAutoDetect = autodetectSiteDir(workingDirectory)
val siteFromAutoDetect = if (config.site.isEmpty) { autodetectSiteDir(workingDirectory) } else { None }
val errOrSiteFromCliArgs: Either[ErrorReport, Option[File]] = Option(cliArgs.site) match {
case Some(siteDirFromCliArgs) =>
val f = new File(siteDirFromCliArgs)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/s3/website/model/push.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ object Upload {
}

object Files {
def recursiveListFiles(maxDepth: Int = Integer.MAX_VALUE)(f: File): Seq[File] = {
def recursiveListFiles(f: File): Seq[File] = {
val these = f.listFiles
if (these != null)
these ++ these.filter(_.isDirectory).flatMap(recursiveListFiles(maxDepth - 1))
these ++ these.filter(_.isDirectory).flatMap(recursiveListFiles)
else
Nil
}
Expand All @@ -137,7 +137,7 @@ object Files {
if (doNotUpload) logger.debug(s"Excluded $s3Key from upload")
doNotUpload
}
recursiveListFiles()(site.rootDirectory)
recursiveListFiles(site.rootDirectory)
.filterNot(_.isDirectory)
.filterNot(f => excludeFromUpload(site.resolveS3Key(f)))
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/s3/website/model/ssg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ trait Ssg {
object Ssg {
val automaticallySupportedSiteGenerators = Jekyll :: Nanoc :: Nil

val maxAutodetectDepth = automaticallySupportedSiteGenerators.map(_.outputDirectory).map(_.split(File.separatorChar).length).max

def autodetectSiteDir(workingDirectory: File): Option[File] =
recursiveListFiles(maxAutodetectDepth)(workingDirectory).find { file =>
recursiveListFiles(workingDirectory).find { file =>
file.isDirectory && automaticallySupportedSiteGenerators.exists(ssg => file.getAbsolutePath.endsWith(ssg.outputDirectory))
}
}
Expand Down

0 comments on commit 8398a92

Please sign in to comment.