Esempio n. 1
0
// Forces nyfikend to check all pages immediately.
func force(bw *bufioutil.Writer) (err error) {
	// Send nyfikend a query to force a recheck.
	_, err = bw.WriteLine(settings.QueryForceRecheck)
	if err != nil {
		return errutil.Err(err)
	}

	fmt.Println("Pages will be checked immediately by your demand.")
	return nil
}
Esempio n. 2
0
// Receive updates from nyfikend.
func getUpdates(bw *bufioutil.Writer, conn net.Conn) (ups map[string]bool, err error) {
	// Ask for updates.
	_, err = bw.WriteLine(settings.QueryUpdates)
	if err != nil {
		return nil, errutil.Err(err)
	}

	// Will read from network.
	dec := gob.NewDecoder(conn)

	// Decode (receive) the value.
	err = dec.Decode(&ups)
	if err != nil {
		return nil, errutil.Err(err)
	}
	return ups, nil
}
Esempio n. 3
0
// Removes all updates.
func clearAll(bw *bufioutil.Writer, conn net.Conn) (err error) {
	ups, err := getUpdates(bw, conn)
	if err != nil {
		return errutil.Err(err)
	}

	for up := range ups {
		u, err := url.Parse(up)
		if err != nil {
			return errutil.Err(err)
		}

		urlAsFilename := u.Host + u.Path + u.RawQuery
		fname, err := filename.Encode(urlAsFilename)
		if err != nil {
			return errutil.Err(err)
		}

		cacheFile, err := os.Open(settings.CacheRoot + fname + ".htm")
		if err != nil {
			return errutil.Err(err)
		}
		defer cacheFile.Close()
		readFile, err := os.Create(settings.ReadRoot + fname + ".htm")
		if err != nil {
			return errutil.Err(err)
		}
		defer readFile.Close()

		_, err = io.Copy(readFile, cacheFile)
		if err != nil {
			return errutil.Err(err)
		}

		// Debug
		debugCacheFile, err := os.Open(settings.DebugCacheRoot + fname + ".htm")
		if err != nil {
			return errutil.Err(err)
		}
		defer cacheFile.Close()
		debugReadFile, err := os.Create(settings.DebugReadRoot + fname + ".htm")
		if err != nil {
			return errutil.Err(err)
		}
		defer readFile.Close()

		_, err = io.Copy(debugReadFile, debugCacheFile)
		if err != nil {
			return errutil.Err(err)
		}
	}

	// Send nyfikend a query to clear updates.
	_, err = bw.WriteLine(settings.QueryClearAll)
	if err != nil {
		return errutil.Err(err)
	}

	fmt.Println("Updates list has been cleared!")
	return nil
}