Warning: session_start(): open(/var/lib/php/sessions/sess_o14n8ph31tp1aokr7fiq9db96h, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
srecord noeq PicturesByMD5(File dir) > MetaWithChangeListeners {
settable S extension = ".jpeg";
transient Lock lock = lock();
// current count of images (calculated lazily)
transient Int imageCount;
File imageFile(S md5) {
ret newFile(dir, assertMD5(md5) + extension);
}
bool has(S md5) { ret isFile(imageFile(md5)); }
BufferedImage get(S md5) {
ret decodeImage(imageFile(md5));
}
swappable BufferedImage decodeImage(File f) {
ret loadImage2(f);
}
bool put(S md5, byte[] imageData) {
// double-checked locking, yay!
if (has(md5)) false;
lock lock;
if (has(md5)) false;
saveBinaryFile(imageFile(md5), imageData);
if (imageCount != null) imageCount.set(imageCount+1);
true;
}
// -actually scans the directory
// -only sees files with the correct extension
int freshImageCount() {
lock lock;
imageCount(l(listFilesWithExtension(dir, extension)));
ret imageCount;
}
// get current image count in an efficient way
// -does not notice when other objects/processes
// add or remove images in the directory
int imageCount() {
lock lock;
if (imageCount == null)
freshImageCount();
ret imageCount;
}
selfType imageCount(int n) {
imageCount = n;
change();
this;
}
transient simplyCached FieldVar varImageCount() {
ret new FieldVar(l0 imageCount, l1 imageCount);
}
}