internal ZipOutputStream m_zipOut; // write only #endregion Fields #region Constructors private Zip(File f) { try { // only support local files if (!(f is LocalFile)) throw IOErr.make("Only local files supported: " + f).val; // open the file this.m_file = (LocalFile)f; this.m_zipFile = new ZipFile(m_file.m_file.FullName); } catch (System.Exception e) { // NOTE: use ctor instead of make() to force type == IOErr throw new IOErr(e).val; } }
static Map readDef(Pod pod, Uri uri) { uri = Uri.fromStr(pod.uri() + "/" + uri); Fan.Sys.File f = (Fan.Sys.File)pod.file(uri, false); Map map = Sys.m_emptyStrStrMap; try { if (f != null) { map = (Map)f.readProps().toImmutable(); } } catch (System.Exception e) { System.Console.WriteLine("ERROR: Cannot load props " + pod + "::" + uri); System.Console.WriteLine(" " + e); } return(map); }
////////////////////////////////////////////////////////////////////////// // Public ////////////////////////////////////////////////////////////////////////// public Type compile(File file, Map options) { // normalize the file path as our cache key file = file.normalize(); // unless force=true, check the cache if (!getOption(options, m_strForce, false)) { CachedScript c = getCache(file); // if cached, try to lookup type (it might have been GCed) if (c != null) { Type t1 = Type.find(c.typeName, false); if (t1 != null) return t1; } } // generate a unique pod name string podName = generatePodName(file); // compile the script Pod pod = compile(podName, file, options); // get the primary type List types = pod.types(); Type t = null; for (int i=0; i<types.sz(); ++i) { t = (Type)types.get(i); if (t.isPublic()) break; } if (t == null) throw Err.make("Script file defines no public classes: " + file).val; // put it into the cache putCache(file, t); return t; }
string cacheKey(File f) { return f.toStr(); }
void putCache(File file, Type t) { CachedScript c = new CachedScript(); c.modified = file.modified(); c.size = file.size(); c.typeName = t.qname(); lock (m_cache) { m_cache[cacheKey(file)] = c; } }
////////////////////////////////////////////////////////////////////////// // CachedScript ////////////////////////////////////////////////////////////////////////// CachedScript getCache(File file) { lock (m_cache) { // check cache string key = cacheKey(file); CachedScript c = (CachedScript)m_cache[key]; if (c == null) return null; // check that timestamp and size still the same if (OpUtil.compareEQ(c.modified, file.modified()) && OpUtil.compareEQ(c.size, file.size())) return c; // nuke from cache m_cache.Remove(key); return null; } }
public override File moveTo(File to) { throw IOErr.make("ZipEntryFile is readonly").val; }
public override File moveTo(File to) { if (isDir() != to.isDir()) { if (isDir()) throw ArgErr.make("moveTo must be dir `" + to + "`").val; else throw ArgErr.make("moveTo must not be dir `" + to + "`").val; } if (!(to is LocalFile)) throw IOErr.make("Cannot move LocalFile to " + to.@typeof()).val; LocalFile dest = (LocalFile)to; if (dest.exists()) throw IOErr.make("moveTo already exists: " + to).val; try { if (m_file is FileInfo) (m_file as FileInfo).MoveTo((dest.m_file as FileInfo).FullName); else (m_file as DirectoryInfo).MoveTo((dest.m_file as DirectoryInfo).FullName); } catch (System.IO.IOException) { throw IOErr.make("moveTo failed: " + to).val; } return to; }
public virtual Type compileScript(File file, Map options) { return m_scripts.compile(file, options); }
public static Process make(List command, File dir) { return new Process(command, dir); }
private Process(List command, File dir) { this.command(command); this.dir(dir); }
public void dir(File v) { checkRun(); if (v != null && (!v.exists() || !v.isDir())) throw ArgErr.make("Invalid working directory: " + v).val; this.m_dir = v; }
////////////////////////////////////////////////////////////////////////// // Construction ////////////////////////////////////////////////////////////////////////// public static Zip open(File file) { return new Zip(file); }
private Pod compile(string podName, File f, Map options) { // use Fantom reflection to run compiler::Main.compileScript(File) Method m = Slot.findMethod("compiler::Main.compileScript", true); return (Pod)m.call(podName, f, options); }
////////////////////////////////////////////////////////////////////////// // Utils ////////////////////////////////////////////////////////////////////////// public File tempDir() { if (m_tempDir == null) { m_tempDir = Env.cur().tempDir().plus(Uri.fromStr("test/"), false); m_tempDir.delete(); m_tempDir.create(); } return m_tempDir; }
////////////////////////////////////////////////////////////////////////// // Utils ////////////////////////////////////////////////////////////////////////// private string generatePodName(File f) { string bse = f.basename(); StringBuilder s = new StringBuilder(bse.Length+6); for (int i=0; i<bse.Length; ++i) { int c = bse[i]; if ('a' <= c && c <= 'z') { s.Append((char)c); continue; } if ('A' <= c && c <= 'Z') { s.Append((char)c); continue; } if (i > 0 && '0' <= c && c <= '9') { s.Append((char)c); continue; } } lock (m_counterLock) { s.Append('_').Append(m_counter++); } return s.ToString(); }
////////////////////////////////////////////////////////////////////////// // State ////////////////////////////////////////////////////////////////////////// public virtual Type compileScript(File file) { return compileScript(file, null); }