1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Versioning to pester the user not to write to incompatible queues.
//!
use ;
use io;
use Path;
use crateMutex;
// fn get_version_for_queue<P: AsRef<Path>>(base: P) -> io::Result<Version> {
// let version_file_contents = read_to_string(base.as_ref().join("yaque-version"))?;
// let version_string = version_file_contents.trim();
// match version_string.parse() {
// Ok(version) => Ok(version),
// Err(err) => panic!(
// "failed to parse `{:?}` version file: {}; contents were `{}`",
// base.as_ref().join("yaque-version"),
// err,
// version_file_contents
// ),
// }
// }
// /// Panics if the queue is not compatible with the current version.
// pub fn panic_if_queue_incompatible<P: AsRef<Path>>(base: P) -> io::Result<()> {
// let version = get_version_for_queue(base.as_ref())?;
// let requirement = VersionReq::parse(&format!(
// "{}.{}.*",
// env!("CARGO_PKG_VERSION_MAJOR"),
// env!("CARGO_PKG_VERSION_MINOR")
// ))
// .expect("requirement is valid");
// if !requirement.matches(&version) {
// panic!(
// "queue `{:?}` is of version {}, but you have yaque version {}, which is compatible with {}",
// base.as_ref(),
// version,
// env!("CARGO_PKG_VERSION"),
// requirement
// );
// } else {
// Ok(())
// }
// }
// /// Sets the version of the queue, if one doesn't exist yet.
// pub fn set_version_for_queue<P: AsRef<Path>>(base: P) -> io::Result<()> {
// let version_file = OpenOptions::new()
// .create_new(true)
// .write(true)
// .open(base.as_ref().join("yaque-version"));
// match version_file {
// Ok(mut file) => {
// writeln!(file, "queue `{:?}` version is {}", base.as_ref(), env!("CARGO_PKG_VERSION"))
// }
// Err(err) if err.kind() == io::ErrorKind::AlreadyExists => Ok(()),
// Err(err) => Err(err),
// }
// }
/// Gets the version of the queue, or sets it if there is not one and then checks if the version is
/// compatible with the current loaded version of `yaque`. It uses a mutex to implement atomicity
/// (yes, we have had some race conditions during testing), but, for the sake of API compatibility
/// in [`crate::Sender::open`] and [`crate::Receiver::open`], it performs a spin lock, instead of
/// `.await`ing.